Show TOC Start of Content Area

Function documentation Portlet Sessions  Locate the document in its SAP Library structure

Use

Similarly to HTTP sessions, portlet sessions enable consecutive requests from a particular client to be associated to portlets in one portlet application.

Integration

Each portlet session is associated with one HTTP session. When attributes are stored in the portlet session they are visible in the HTTP session and vice versa. When the portlet session is invalidated, the HTTP session is also invalidated and vice versa. Creating a new portlet session will result in creating a new HttpSession on which the portlet session is based.

Thus, portlets, servlets, and JSPs within the same portlet application share the same HTTP session. However, this is the HTTP session of the portlet application and it differs from the sessions of the other portlet and Web applications aggregated by the portal as well as from the portal’s HTTP session.

Features

Session Scopes

Portlets in the same portlet application share objects using the APPLICATION_SCOPE of the PortletSession. The ability of portlets to communicate with each other in a specification-compliant way is called inter-portlet communication (IPC).

Each portlet window on a portal page has a private scope, called the PORTLET_SCOPE, that is, if one portlet has two occurrences (portlet windows ) on one portal page, the two portlet windows will have different portlet scopes.

Example

In the Web application session scope, every component of the Web application can access the information stored in the session scope. The information can be used to share a transient state among different components of the same Web application, for example between portlets, or between a portlet and a servlet.

The following is an example of how the setAttribute method of the PortletSession interface can be used to bind an object to the session in the specified scope:

PortletSession session = request. getPortletSession(true);

URL url = new URL(“http://www.someurl.com”);

session.setAttribute(“url1.url”,url,PortletSession.APPLICATION_SCOPE);

session.setAttribute(“bkg.color”,”RED”,PortletSession.PORTLET_SCOPE);

Note

Before accessing the attributes in the portlet session, the portlet calls getPortletSession on the request object.

The session reference is request-bound, thus portlets should not rely on storing references to portlet session objects and reusing them later.

 

End of Content Area