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