http://tapestry.apache.org/tapestry5/guide/persist.html
Most instance variables in Tapestry are automatically cleared at the end of each request.
通常每次請求結束,Tapestry會將實例變量清空。
This is important, as it pertains to how Tapestry pages are pooled and shared, over time, by many users.
這很重要,因為Tapestry的頁面是在緩沖池中被許多用戶共享的。
However, you often want to store some persistent data on a page, and have access to it in later requests.
然而,你通常希望在頁面存儲一些持久數據,這樣后面的請求可以得到這些數據。
This is accomplished with the Persist annotation.
This annotation is applied to private instance fields.
@Persist
private int value;
Annotated fields will store their state between requests. Generally, speaking, this means that the value is stored into the session (but other approaches are possible).
Whenever you make a change to a persistent field, its value is stored.
On later requests, the value for such persistent fields is reloaded from storage.
Persistence Strategies
The value for each field is the strategy used to store the field between requests.
session strategy
The session strategy stores field changes into the session; the session is created as necessary.
A suitably long session attribute name is used; it incorporates the name of the page, the nested component id, and the name of the field.
Session strategy is the default strategy used unless otherwise overridden.
Session策略是默認策略。
flash strategy
The flash strategy stores information in the session as well, just for not very long. Values are stored into the session, but then deleted from the session as they are first used to restore a page's state.
The flash is typically used to store temporary messages that should only be displayed to the user once.
client strategy
The field is persisted onto the client; you will see an additional query parameter in each URL (or an extra hidden field in each form).
Client 持久花費的代價要高些,它會在渲染頁面的每個鏈接后面加上數百字節的額外信息。
Client persistence is somewhat expensive. It can bloat the size of the rendered pages by adding hundreds of characters to each link. There is extra processing on each request to de-serialize the values encoded into the query parameter.
Client persistence does not scale very well; as more information is stored into the query parameter, its length can become problematic. In many cases, web browsers, firewalls or other servers may silently truncate the URL which will break the application. 有時URL地址太長會被截掉。
Use client persistence with care, and store a minimal amount of data. Try to store the identity (that is, primary key) of an object, rather than the object itself.