    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 org.apache.tapestry5.ComponentResources;
    016import org.apache.tapestry5.EventConstants;
    017import org.apache.tapestry5.Link;
    018import org.apache.tapestry5.ValueEncoder;
    019import org.apache.tapestry5.ioc.annotations.UseWith;
    020import org.apache.tapestry5.services.ValueEncoderSource;
    021
    022import java.lang.annotation.Documented;
    023import java.lang.annotation.ElementType;
    024import java.lang.annotation.Retention;
    025import java.lang.annotation.Target;
    026
    027import static java.lang.annotation.RetentionPolicy.RUNTIME;
    028import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.PAGE;
    029
    030/**
    031 * Marks a field of a page (not a component) as persistent within the URL, as with a page activation context. The field
    032 * is mapped
    033 * to a query parameter. When component event or page render links are generated for the page,
    034 * additional values will be added to the {@link Link} (via the {@link EventConstants#DECORATE_COMPONENT_EVENT_LINK} or
    035 * {@link EventConstants#DECORATE_PAGE_RENDER_LINK} events).
    036 *
    037 * The field may be of any type; a {@link ValueEncoder} (from the {@link ValueEncoderSource}) will be used to convert
    038 * between client-side and server-side representations. Null values are not added as query parameters (just non-null).
    039 *
    040 * When a page is activated, the mapped fields will receive their values before an {@linkplain EventConstants#ACTIVATE
    041 * activate} event handler method is invoked.
    042 *
    043 * This annotation is an alternative to {@link Persist}.
    044 *
    045 * Fields annotated with ActivationRequestParameter are <em>not</em> considered persistent (its a process parallel to the one
    046 * related to the {@link Persist} annotation). Invoking {@link ComponentResources#discardPersistentFieldChanges()} will
    047 * <em>not</em> affect annotated fields, only assigning them back to null will.
    048 *
    049 * @see RequestParameter
    050 * @see ValueEncoder
    051 */
    052@Target(
    053{ ElementType.FIELD })
    054@Retention(RUNTIME)
    055@Documented
    056@UseWith(
    057{ PAGE })
    058public @interface ActivationRequestParameter
    059{
    060    /** The name of the query parameter, which defaults to the name of the field. */
    061    String value() default "";
    062
    063    /**
    064     * If true then a null value is an error. If false, then a null value will result in no update to the field. Either way,
    065     * a null field value will result in no query parameter added to a  {@linkplain org.apache.tapestry5.Link generated link}.
    066     *
    067     * @since 5.4
    068     */
    069    boolean required() default false;
    070}