Managing Portlet Sessions

Portlets commonly collect state information that you must save between requests from a client. A way to manage this information is to save it as a session attribute. Portlet sessions are similar to web application sessions, and managing their attributes is the conceptual equivalent.

Portlet sessions do have one major difference. Unlike web application sessions, a Portlet session has scope. A session attribute that is placed in the portlet scope is easily accessible only to the portlet that added it.

When you add an attribute to the session, you must specify the level of access to the attribute within the portlet application. Do this through the scope parameter of the portalLib.setPortletSessionAttr() function. This parameter takes an enumerated value of type SessionScopeKind. For example, to add a session attribute that is only accessible to the declaring portlet, use the following function call in the JSF Handler:
portalLib.setPortletSessionAttr("myKey", "myValue", SessionScopeKind.portletScope);

Feedback