4.6.6 PortletSession object
When the user initially accesses a portlet, a PortletSession is created. The portlet session stores transient data associated with an individual use of the portlet. The concrete portlet instance parameterized by the PortletSession is referred to as the User Portlet Instance.
Figure 4-3 The portlet parameterization
The PortletSession object extends from HttpSession and serves much the same purpose. The PortletSession is intended to represent an ongoing conversation between the client and the portlet. To this end, the PortletSession can be used to store information needed between requests. The PortletSession is intended to store data between requests, not between portlets. As such, data stored in the session by one portlet is not accessible by another. The PortletSession is retrieved from the request object as illustrated in Example 4-4. Since a PortletSession object is created when a user logs in, there is no need to create one. However, the getPortletSession(boolean) can be used to create a session for an anonymous user.
Example 4-4 Retrieving a PortletSession
PortletSession session = request.getPortletSession();
![]()
The most important methods of the PortletSession are getAttribute/setAttribute/removeAttribute: these methods allow you to store, retrieve and delete objects in the PortletSession. Objects stored in the PortletSession should be serializable. To be serializable, the class needs to implement the Serializable interface. Object being placed in the session should be serializable in case the session needs to sent to another JVM in the case of failover or load balancing. This will prevent a NotSerializableException.
ibm.com/redbooks