Friday, April 27, 2012

How to get the Page Title and unique name of the current page in WebSphere Portal

There is a very common requirement in almost all the WebSphere Portal project that how to get the Page Title and unique name of the current page.
The WebSphere Portal Server has concept of NavigationSelectionModel SPI that we can use to know about the current page.This SPI is used by the theme to know the page which should be displayed to the user.This can also be used in portlet application. To get the page title and unique name where our portlet is getting rendered.
Below is the snippet of the code:

Step 1. Include portal taglib on JSP
<%@ taglib uri="/WEB-INF/tld/portal.tld" prefix="wps" %>
Step 2. Use <wps:navigation> tag.

<wps:navigation>
   <wps:navigationloop>
    <%if (wpsSelectionModel.isNodeSelected(wpsNavNode)){
String pageTitle = com.ibm.wps.model.LocaleHelper.getTitle
                   ((com.ibm.portal.Localized)wpsNavNode, request);
String uniqueName = wpsNavNode.getContentNode().getObjectID().getUniqueName();        
System.out.println("The pageTitle of the current page : "+pageTitle);
System.out.println("The uniqueName of the current page: "+uniqueName);
}%>
</wps:navigationloop>
</wps:navigation>