Tuesday, March 24, 2009

Use Portal 6.0 Advanced URL Generation Helper Class ServletURLGenerator to Generate URL of portlet

Intention
In some cases, you might want to open a single portlet in a new window in solo state (which hides the portal theme elements, like a banner, page navigation, or tool bar), for example,
This main portlet contains one link, after click the link, the PopUpTest portlet which resides on the XuTest2 page will be displayed on a new window.


The XuTest2 page has more than one portlet:

therefore, the question comes: how to generate url of the target portlet. WebSphere Portal 6.0 provides some advanced URL generation helper classes to solve this problem. I am going to demonstrate the usage of ServeletURLGenerator.generateUrlForFlyout.
Investigating the generateUrlForFlyout function
public static EngineURL generateUrlForFlyout(
String pageName, String portletName,
HttpServletRequest request,
HttpServletResponse response)*
* This is the updated version of the one provide on Portal 6.0.x Advanced URL Generation Helper classes.
This function requires four parameters where
• pageName: the unique name of the target portlet page
• portletName: the unique name of target PortletWindow
To set the unique name of page, you can use either XMLAccess or through “Manage Custom Unique Names” portlet:

To set the unique name of PortletWindow, the only way is through XMLAccess to set the unique name of the component that holds the portlet instance on the page:



About how to do it, please refer to step1-4 of URLGeneration in WebSphere Portal v5.1.x - Linking to another portlet
Restrictions
As we see from the function above, to get it work, the target portlet must be assigned to a known page, which means, this API will not work if the portlet does not map to a page.
Code to generate URL
On the MainPortletView.jsp, we use the following code to generate URL of target portlet:
<%
try {
String pageName = "co.at.profile.XuTest2";
String portletName = "xu.test.popuptest";
EngineURL targetURLStr = ServletURLGenerator.generateUrlForFlyout(
pageName, portletName, request, response);
%>



Link

Of course, to avoid the resolve exceptions, you need to include the necessary classes:
<%@page language="java" contentType="text/html"
pageEncoding="ISO-8859-1" session="false"
import="com.ibm.wps.l2.urlgeneration.helper.*,
com.ibm.portal.state.EngineURL"%>
Resources
Portal 6.0.x Advanced URL Generation Helper classes.
URLGeneration in WebSphere Portal v5.1.x - Linking to another portlet