Thursday, August 30, 2012

Reset Portlet Action-scoped Request Attributes

JSR 286 provides a container runtime option javax.portlet.actionScopedRequestAttributes that when set to true allows portlets set complex objects as request attributes from the processAction method for subsequent rendering.

Based on the spec, action-scoped request attributes are kept in the session until are reset in the next action or session timeout. The reset can be done in different ways:

1) In portlet processAction method, call request.setAttribute(attributeName, null);, this call removes the attribute with the given name.

2) Build a portlet renderURL with a parameter that has name as javax.portlet.as and an empty string value, as shown in below. All action-scoped request attributes will be removed once the renderURL is invoked.

<portlet:renderURL var="refreshURL">
  <portlet:param name="javax.portlet.as" value="" />
</portlet:renderURL>

Apache Tiles 2.2 error handling in Websphere Application Server 7

When using Apache Tiles 2.2 in Websphere 7 application, by default the JSP engine renders the response tile-by-tile. When exception happens in one tile and there is error page defined, only the offending tile is rendered with the error page, the others are just rendered fine.

To change this behaviour to allow exceptions to bubble up to the including JSP and forwad to the error page, there are two things need to be done:

1) Set the container custom property com.ibm.ws.webcontainer.dispatcherRethrowSError to true. This property is avaiable from WAS Fixpack 7.0.0.15. Details can be found from http://www-01.ibm.com/support/docview.wss?uid=swg1PM22919 and http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frweb_custom_props.html.

2) Define an errorPage for the template jsp, as shown in below.

<%@ page errorPage="/jsp/general/error.jsp" %>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<tiles:insertAttribute name="header" />

<tiles:insertAttribute name="body" />

<tiles:insertAttribute name="footer" />