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.http.services.Session;
016import org.apache.tapestry5.ioc.annotations.UseWith;
017
018import java.lang.annotation.Documented;
019import java.lang.annotation.Retention;
020import java.lang.annotation.Target;
021
022import static java.lang.annotation.ElementType.FIELD;
023import static java.lang.annotation.RetentionPolicy.RUNTIME;
024import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
025
026/**
027 * Identifies a field as persistent, meaning its value persists from one request to the next. Different strategies exist
028 * for how this is accomplished, the most common being the default, "session", which stores the field's value in the
029 * {@link Session}.
030 *
031 * In most cases, the value will be omitted and will default to the empty string. This forces a search for the correct
032 * strategy. Starting with the component (or mixin) itself, a check is made for the {@link Meta meta data property}
033 * <code>tapestry.persistence-strategy</code>. If a value is found, it is used, otherwise the search continues up the
034 * inheritance hierarchy, towards the page. If not found, then the "session" strategy is used.
035 *
036 * In this way, the session persistence strategy for a component and all of its sub-components can be controlled by the
037 * containing component.
038 *
039 * @see org.apache.tapestry5.services.MetaDataLocator
040 * @see org.apache.tapestry5.PersistenceConstants
041 * @see ActivationRequestParameter
042 */
043@Target(FIELD)
044@Documented
045@Retention(RUNTIME)
046@UseWith({COMPONENT,MIXIN,PAGE})
047public @interface Persist
048{
049
050    /**
051     * The strategy used to persist the value. The default value, the empty string, allows persistence to be decided by
052     * the containing component and component hierarchy.
053     */
054    String value() default "";
055}