Chaning Portlet title at runtime

I came across many threads where people looking for the solution on how to change portle title at runtime.

Changing portlet title on runtime means on perfroming any action, portlet title( top left most text written on portlet window) should get changed.
The JSR168 Portlet Specification states that a portlet can indicate its preferred title during run time, using the RenderResponse.setTitle(String title) method (Portlet API 1.0).
Because portlets can dynamically set the title during rendering, the title is only available after its content has been rendered. Therefore, the portlet must be rendered first, if you want to have access to the title. However, this requirement conflicts with the requirement that the title be displayed on the portal page before the portlet content.

Here is how you can achieve this
write this code on your jsp

VAR dynamicTitle = "Portlet New Title";
var titleElement = document.getElementById("title.tag");
if (titleElement != null) {
if (dynamicTitle != "" && dynamicTitle != "null")
titleElement.innerHTML = dynamicTitle ;
Also have a look at this tech note.

No comments: