Show TOC

Background documentationManaging State Locate this document in the navigation structure

 

Portal applications are stateless by nature. The Portal Runtime (PRT) API provides a number of objects (contexts), in which a portal component or service can manage the application state. You decide which context to use depending on the required scope: session, component or request.

Session Scope

The scope of this context is a user session; you use it to share data between different requests and applications during a single session.

The HttpSession object represents a session of the PRT Dispatcher servlet. For background information, see How Requests Are Handled by Server.

You can access this object from any portal component using the IPortalComponentRequest.getServletRequest().getSession() method.

For example, a portal component stores a string in the HttpSession object by calling

IPortalComponentRequest.getServletRequest().getSession().putValue(“name”, “SAP”);

Another portal component can retrieve this string by calling IPortalComponentRequest.getServletRequest().getSession().getValue(“name”);

Component Scope

IPortalComponentSession Context

The IPortalComponentSession context represents a specific portal component session. You can access it only from a portal component running in a portal application by calling the IPortalComponentRequest.getComponentSession() method. This context is valid while the component session is valid. It can be used, for example, to share the state of a wizard across its steps.

For storing and sharing data in the IPortalComponentSession context, use the IPortalComponentSession.putValue(String name, Object value) and IPortalComponentSession.getValue(String name) methods respectively.

IPortalComponentContext Context

The IPortalComponentContext context represents an iView based on a portal component. This context can be accessed from the portal component using the IPortalComponentRequest.getComponentContext() method.

This context provides access to the IPortalComponentProfile object, which is stored in the Portal Content Directory (PCD), so the data in this object is persistent. To access IPortalComponentProfile, call the IPortalComponentContext.getProfile() method.

Request Scope

The IPortalComponentRequest context represents a single HTTP request and response cycle. You can use it for sharing data within a request cycle between all components running in the same cycle.

The INode object represents a portal component node in the Portal Object Model (POM) – a tree of the portal components that is built for each request. For more information, see How Requests Are Handled by Portal Runtime.

You can use the node object to store data that you want to use later at the rendering stage. For storing and sharing data in the INode object, use the IPortalComponentRequest.getNode().putValue(“name”, obj) and IPortalComponentRequest.getValue(“name”) methods respectively.

Dependencies

The APIs for accessing these contexts are available in the following packages:

  • Package: com.sap.portals.portal.prt.component

    Interfaces: IPortalComponentContext, IPportalComponentRequest, IPortalComponentSession, IPortalComponentProfile

  • Package: com.sapportals.portal.prt.pom

    Interface: INode

  • Java API: javax.servlet.http.HttpSession