One of the most useful features
of a portlet is that it can communicate
with other portlets. Although the standard portlet API does not define
a communication
mechanism, you can use the PortletSession as a “scratchpad” for passing
information.
The PortletSession is the mechanism that the portal uses for identifying
and
storing transient information about a user across multiple browser
requests.
One portlet in an application can write to the PortletSession, and
the other
portlets in the application can read the values and use them.
The
portlet request lifecycle makes communication of this sort possible.
When user interaction occurs on a portal page, the following sequence
of events
happens:
- The portlet where the event occurred processes the
event first. This
portlet can add attributes to the application scope of the session.
The attribute
will then be accessible to all portlets in the application.
- After
the portlet finishes responding to the event, each portlet on the
page, including the one that handled the event, renders itself. While
rendering,
all portlets can access the application scope attribute and use it
to appropriately
respond to the user action.