Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added simple exmamples for @Persist. Rewording lead paragraphs for clarity. Wishing the word "persistence" weren't so overloaded.
Wiki Markup
{float:right|background=#eee}
{contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=persistence}
{float}

Persistent Page Data

Info

The use of the term "persistence" here refers to page-level persistence, NOT database persistence.

Most instance variables in Tapestry are automatically cleared at the end of each request. This is important, as it pertains to how Tapestry pages are shared, over time, by many users.

However, you often want to store some persistent data on a single page, and have access to it in later requests . Long term storage of data should go in a database of some form, but server-side state for the duration of the as user's interaction with the application should go in the HttpSession (though Tapestry provides a few other options as well).

Note: To store values that may be accessed across multiple pages, uses a session state object.

Making a field persistent is accomplished with the Persist annotation. Again, this does not refer to database persistence, it refers to session persistence.

to that same page, without having to store it in a database between requests. (To store values across multiple pages, see Session Storage.)

Making page data persist across requests to a single page is accomplished with the @Persist annotation. This annotation is applied to private instance fields of components.:

Code Block
java
java
  @Persist
  private int value;

Annotated Such annotated fields will store retain 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 storedsaved. On later requests to the same page, the value for such persistent fields is reloaded from storagethe field is restored.

Persistence Strategies

The value for each field is the strategy used to store the field between requests.

...

Session strategy is the default strategy used unless otherwise overridden.

Code Block
titleExample: Session Strategy

  @Persist
  private into value;

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.

Code Block
titleExample: Flash Strategy

  @Persist("flash")
  private into value;

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).

...

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.

Code Block
titleExample: Client Strategy

  @Persist("client")
  private into value;

Persistence Strategy Inheritance

...