Enable two phase rendering in portlet

Starting from JSR 286 (Portlet Specification 2.0), portlets support two phase rendering and it defines doHeaders() method that you can implement if you want to do one of the following things


  • Change title of the portal page

  • Add header

  • Add cookie



The two phase request processing is disabled by default, you can enable it by setting value of javax.portlet.renderHeaders container run time option to true like this


<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="v2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>Two phase rendering portlet</portlet-name>
<portlet-class>com.ibm.webspherenotes.jsr286.TwoPhaseRenderingPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>

</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Two phase rendering Portlet</title>
<short-title>Two phase rendering Portlet</short-title>
<keywords>twophase</keywords>
</portlet-info>
</portlet>
<container-runtime-option>
<name>javax.portlet.renderHeaders</name>
<value>true</value>
</container-runtime-option>

</portlet-app>

1 comment: