001 // Copyright 2006, 2007, 2008 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.annotations;
016
017 import org.apache.tapestry.TapestryConstants;
018
019 import java.lang.annotation.Documented;
020 import java.lang.annotation.ElementType;
021 import java.lang.annotation.Retention;
022 import static java.lang.annotation.RetentionPolicy.RUNTIME;
023 import java.lang.annotation.Target;
024
025 /**
026 * Marks a method as a handler for a client side event. The handler method will be invoked when a component triggers an
027 * event. Filters on the type of event and on the originating component ensure that only the appropriate methods are
028 * invoked.
029 * <p/>
030 * Client events include a <em>context</em> of one or more values. These context values are included in the action URI.
031 * The values are optionally supplied to the handler method as parameters. Automatic {@linkplain
032 * org.apache.tapestry.ValueEncoder conversion} from string to the type of the actual parameter occur.
033 * <p/>
034 * Handlers may return a value. Returning a non-null value will abort the handling of the event, and will usually
035 * control the response sent to the client web browser. The details are somewhat specific to the type of event and the
036 * component involved.
037 * <p/>
038 * If a handler is not found within the originating component (or no handler aborts the event handling), then handlers
039 * within the containing component will be searched. This continues up the page hierarchy. In some cases, having no
040 * handlers (or no aborting handlers) is considered acceptible; in others, it is an error. Again, this is defined by the
041 * type of originating component, and the type of event.
042 * <p/>
043 * <strong>If you fail to provide filters on either component or event type, then your method will be invoked for all
044 * component events, possibly including events that bubble up from embedded sub-components. </strong>
045 */
046 @Target(ElementType.METHOD)
047 @Retention(RUNTIME)
048 @Documented
049 public @interface OnEvent
050 {
051
052 /**
053 * The event type to match. The handler will only be invoked if the client event type matches the value. The default
054 * value is "action". Matching is case-insensitive.
055 */
056 String value() default TapestryConstants.ACTION_EVENT;
057
058 /**
059 * The local id of the component from which the event originates. If not specified, then the default is to match any
060 * component. If an event from a component is not handled in the component's container, it is re-triggered inside
061 * the component's grand-container and will appear to originate from the container. Thus events that escape a
062 * component will appear to originate in the component's container, and so forth.
063 * <p/>
064 * <p/>
065 * Matching by component id is case insensitive.
066 */
067 String component() default "";
068
069 }