Friday, April 13, 2007

Communciating between JSR-168 portlets and the portal containter

The JSR-168 spec does not address the need for portlets and the portlet container to communicate. Sometimes an action taken by a portlet needs to be reflected in the navigation which is controlled by the container. Conversely, an action taken in the navigation will need to change the state of the portlets. The following information applies specifically to Vignette Application Portal but should apply to other portals like Pluto, Jetspeed2 and Liferay. Communicating from the portlets to the portal container. Add a parameter to PortletURL. Then there can be something (grid, secondary page or my personal choice, a servlet filter) that is listening for that parameter. Of course, the portlet will add a lot of nonsense to the name of the parameter so the receiver needs to look for something ending with the parameter name. The servlet filter can then place the required information into the session. Of course, you need to take reasonable security into account when deciding what to pass as a parameter. Communicating from the portal to a a portlet. Again, in a servlet filter, add the information that needs to be communicated to the portlets as a request attribute. The trick is that the name of the attribute must begin with "javax.servlet.". It will be visible in the RenderRequest and ActionRequest objects passed to the portlet. We are already doing this to pass things like Remote URL to the portlets. Note: For this to work the object being passed needs to be in the classpath and not just loaded in the WAR file. The reason is that the object is loaded by one classloader and then passed to another. You end up with ClassCastException.

No comments: