Monday, August 12, 2013

Changing or setting up Page Title of a JSR-286 Portlet dynamically

Hello Friends,

To write into the HTML head section of your JSR 286 portlet, for example, to change a page title, use the addProperty method on the PortletResponse.

Invoke the addProperty method to modify the HTML head section.

PortletReponse.addProperty(String key, org.w3c.dom.Element element)

Note: When modifying the HTML head section, you must invoke the addProperty method before the response headers are committed. This should occur no later than during the render headers sub phase of the render lifecycle phase.

Example:

protected void doHeaders(RenderRequest request, RenderResponse response)
{
    Element title = response.createElement("title");
    title.setTextContent("My Portal Page Title");
    response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, title);
}

Thanks,
Chirag

Setting headers for a JSR 286 portlet

Hello Friends,


To set HTTP header information in your JSR 286 portlet, use the setProperty and addProperty methods of the PortletResponse.

Specify the appropriate method, depending on whether you want to overwrite or append key values.

setProperty(String key, String value): Overwrites all previous values for the given key.
addProperty(String key, String value): Attempts to append the key value.

When setting headers in the render lifecycle phase, portlets should set the header in the render headers part or simply override the GenericPortlet.doHeaders method to make sure the server's response headers have not already been committed. Note, however, that the delivery of HTTP headers to the client cannot be guaranteed, because other portlets on a page might override it or the setting of some header attributes might be against the portal's policy.

Thanks,
Chirag

Two-Phase rendering support in IBM WebSphere Portal 7.0 and 8.0 with JSR 286 Portlets.

Hello Friends,

When you work on portlets there are certain challenges when it comes to setting up cookies, http headers or changing the page title dynamically. IBM WebSphere Portal with JSR-286 portlets can solve this problem by enabling Two-Phase Rendering.

By default, two-phase rendering is turned off. To enable two-phase rendering for a portlet, you must update the portlet.xml deployment descriptor for the portlet.

Add the following entry to the file:

<portlet>
...
<container-runtime-option>
<name>javax.portlet.renderHeaders</name>
<value>true</value>
</container-runtime-option>
</portlet>

Enjoy,
Chirag Rana