001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.annotations;
014
015import static java.lang.annotation.RetentionPolicy.RUNTIME;
016import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.COMPONENT;
017import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.PAGE;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.Target;
023
024import org.apache.tapestry5.ioc.annotations.UseWith;
025
026/**
027 * <p>
028 * Marks an event handler method to be published as an event to be called in JavaScript
029 * through the <code>t5/core/ajax</code> function when the <code>options</code>
030 * parameter has an <code>element</code> attribute.
031 * <p>
032 * 
033 * <p>
034 * The logic for obtaining the URL is actually located implemented in the
035 * <code>t5/core/dom.getEventUrl(eventName, element)</code> function.
036 * </p>
037 * 
038 * <p>
039 * The event information is stored in JSON format inside the 
040 * {@value org.apache.tapestry5.TapestryConstants#COMPONENT_EVENTS_ATTRIBUTE_NAME} attribute.
041 * </p>
042 * 
043 * <p>
044 * When used in a component method, the component must render at least one element,
045 * and that's what gets the
046 * {@value org.apache.tapestry5.TapestryConstants#COMPONENT_EVENTS_ATTRIBUTE_NAME} attribute above. 
047 * If it doesn't, an exception will be thrown.
048 * </p>
049 * 
050 * <p>
051 * When used in a page method, the page must render an &lt;body&gt; element. If it doesn't,
052 * an exception will be thrown.
053 * </p>
054 * 
055 * @since 5.4.2
056 * @see <a href="https://tapestry.apache.org/ajax-and-zones.html#AjaxandZones-Invokingserver-sideeventhandlermethodsfromJavaScript">Invoking server-side event handler methods from JavaScript</a>
057 */
058@Target(ElementType.METHOD)
059@Retention(RUNTIME)
060@Documented
061@UseWith({ COMPONENT, PAGE })
062public @interface PublishEvent
063{
064}