JSR 286 Container Runtime Options

In JSR 168 portlet, when we require to pass parameter from processAction to render phase, we use setRenderParameter on actionResponse and then in render phase ( doView) we get the same parameter using renderRequest.getParameter(<paramname>).

As an alternate we also make use of session to pass data between these two phase ( action and render).

The issue with session approach is, we have to take care about managing session attributes because container is not going to manage session attributes.

JSR 286 specification provides Container Runtime options
1. javax.portlet.renderHeaders

2. javax.portlet.servletDefaultSessionScope
3. javax.portlet.escapeXml
4. javax.portlet.actionScopedRequestAttributes

If we look at last one, that is actionScopedRequestAttributes, with this actionScopedRequestAttributes, we can store object into actionRequest in processAction and the same can be retrieved in render Phase (doView) from request using renderRequest.getAttribute(<key>);

To achive this, we need to make an entry in portlet.xml and that entry tells container to perform the same.

<container-runtime-option> <name>javax.portlet.actionScopedRequestAttributes</name> <value>true</value>
<key>numberOfCachedScopes</key>
<value>5</value>
</container-runtime-option>

Above entry can set at portlet level or at application level.

If you want to set it at application level, write above entry outside <portlet> tag and inside </portlet-app> tag,
and if you want to set it at portlet level, write above entry inside <portlet>. tag

No comments: