inter-portlet communication ,portlet之间的交互通讯,Transient State Management

来源:互联网 发布:状态模式 java 编辑:程序博客网 时间:2024/06/05 20:04
Transient State Management

JSR-168 portlets have access to two different kinds of transient state:
session state and navigational state.


Session State


Session state is available to the portlet for each user and allows the portlet
to store information needed across multiple user requests.When storing data in the
session one of two sessions scopes can be used: portlet scope or web application
scope.

Attributes stored within the portlet scope are visible only to the portlet
that set them, while attributes set within the web application scope are visible
to all other components within the same web application(servlets,jsps,other portlets,etc.).
At this time, web application-scoped session attributes are the only standard
mechanism by which transient state can be shared by different portlets(
inter-portlet communication). The default scope is portlet scope which will
keep data private to the portlet.

Since the portlet session is essentially a long-lived,in-memory object it is
important that developers be very judicious about what is stored in session.
Data which is appropriate for storing in the portlet session is that which is
user specific and cannot be recreated by any other means.Whenever possibly,
session attributes should be explicitly removed from the session when they
are no longer needed.

At run-time,session state can be accessed via the PortletSession object.
The PortletSession object can be retrieved by calling the getPortletSession()
method in the PortletRequest. Session attributes are represented by name/value
pairs where the name is always a string and the value is any java object.



Navigational State


Navigational state defines how the current view of the portlet is rendered and
is specific to each portlet instance. The navigational state consists of the
portlet mode,window state and any render parameters(render parameters are a
collection of string-based name/value pairs).The navigational state can be read
at any time,but it can be changed only in the processing of an action request
or by clicking on a render link that has specified new navigational state
parameters.

During the processing of an action request,the developer can change the
navigational state via the following methods on the ActionResponse object:
.setPortletMode()
.setRenderParameter()
.setRenderParameters()
.setWindowState()

To change the navigational state via a render link,the renderURL tag can be
used:
<portlet:renderRUL portletMode="edit" windowState="maximized">
    <portlet:param name="foo" value="bar">
</portlet:renderURL>

This example creates a render URL that,when clicked by the user,will change
the portlet mode to edit,the window state to maximized and will add a
"foo=bar" render parameter.

It is important to note that the same navigational state will be passed to
the portlet for every render request until it is explicitly changed via
one of the methods described above.