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 | ||||
---|---|---|---|---|
| ||||
public class MyPage { @SessionState private ShoppingCart shoppingCart; . . . } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
@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 | ||||
---|---|---|---|---|
| ||||
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.
...