Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin


 

Most web applications will need to have some data that is shared across multiple pages. Perhaps you are creating a multi-page wizard, or you have an object that tracks the user's identify once logged in, or maybe you need to manage a shopping cart.

...

A field holding an SSO is marked with the @SessionState annotation.

Wiki Markup
{float:right}
{panel:background=#eee|title=Contents}
{toc:minLevel=2|maxLevel=4}
{panel}
{float}

Example:


Code Block
languagejava
titleMyPage.java (partial)
public class MyPage
{
  @SessionState
  private ShoppingCart shoppingCart;
  
  . . .
}

...

Code Block
languagejava
titleExample of Data Collision -- Don't Do This!
  @SessionState
  private String userName;     // Unsafe -- String is not a custom type

  ... then, later in this class or any other:

  @sessionState@SessionState
  private String userCity;     // This overwrites value in userName, because it's also a String!

...

Session Attributes

 
Since
since5.2

As an alternative to SSOs, Tapestry provides a Session Attribute mechanism, which lets you store data in the session by name (rather than type). It is particularly useful when integrating Tapestry with legacy applications that directly manipulate the HttpSession.

...