Tuesday, March 20, 2012

Dynamic Portlet Title in JSR286 portlet

Dear All,

I recently came across a need to achieve dynamic portlet title. I came across many articles and methodologies. But bellow one is the simplest and most elegant one that I used.

As per JSR286 portlet specification, we are allowed to override getTitle method of GenericPortlet

Ref: http://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/GenericPortlet.html#getTitle%28javax.portlet.RenderRequest%29

so I placed following method in my Porlet Class which extends GenericPortlet


public java.lang.String getTitle(RenderRequest request) {
return "My custom title";
}


The execution of this getTitle is subject to container runtime settings. So dont forget to set javax.portlet.renderHeaders to true under container-runtime-option in portlet.xml


Now you can extend this concept by retrieving a portlet preferences and use it as portlet title.

No comments:

Post a Comment