    001// Copyright 2006, 2007, 2008, 2009 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
    015package org.apache.tapestry5.annotations;
    016
    017import org.apache.tapestry5.EventConstants;
    018import org.apache.tapestry5.ioc.annotations.UseWith;
    019import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
    020
    021import java.lang.annotation.Documented;
    022import java.lang.annotation.ElementType;
    023import java.lang.annotation.Retention;
    024import static java.lang.annotation.RetentionPolicy.RUNTIME;
    025import java.lang.annotation.Target;
    026
    027/**
    028 * Marks a method as a handler for a client side event. The handler method will be invoked when a component triggers an
    029 * event. Filters on the type of event and on the originating component ensure that only the appropriate methods are
    030 * invoked.
    031 * <p/>
    032 * Client events include a <em>context</em> of one or more values. These context values are included in the action URI.
    033 * The values are optionally supplied to the handler method as parameters. Automatic {@linkplain
    034 * org.apache.tapestry5.ValueEncoder conversion} from string to the type of the actual parameter occur.
    035 * <p/>
    036 * Handlers may return a value. Returning a non-null value will abort the handling of the event, and will usually
    037 * control the response sent to the client web browser. The details are somewhat specific to the type of event and the
    038 * component involved.
    039 * <p/>
    040 * If a handler is not found within the originating component (or no handler aborts the event handling), then handlers
    041 * within the containing component will be searched. This continues up the page hierarchy. In some cases, having no
    042 * handlers (or no aborting handlers) is considered acceptible; in others, it is an error. Again, this is defined by the
    043 * type of originating component, and the type of event.
    044 * <p/>
    045 * <strong>If you fail to provide filters on either component or event type, then your method will be invoked for all
    046 * component events, possibly including events that bubble up from embedded sub-components. </strong>
    047 */
    048@Target(ElementType.METHOD)
    049@Retention(RUNTIME)
    050@Documented
    051@UseWith({COMPONENT,MIXIN,PAGE})
    052public @interface OnEvent
    053{
    054
    055    /**
    056     * The event type to match. The handler will only be invoked if the client event type matches the value. The default
    057     * value is "action".  Matching is case-insensitive.
    058     *
    059     * @see org.apache.tapestry5.EventConstants
    060     */
    061    String value() default EventConstants.ACTION;
    062
    063    /**
    064     * The local id of the component from which the event originates. If not specified, then the default is to match any
    065     * component. If an event from a component is not handled in the component's container, it is re-triggered inside
    066     * the component's grand-container and will appear to originate from the container. Thus events that escape a
    067     * component will appear to originate in the component's container, and so forth.
    068     * <p/>
    069     * Matching by component id is case insensitive.
    070     */
    071    String component() default "";
    072}