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