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

本文介绍如何在 WebSphere Portal 6.0 中使用 ServeletURLGenerator 类的 generateUrlForFlyout 方法为特定的 Portlet 生成 URL,以便在新窗口中打开。此方法适用于希望在独立状态下显示 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:

<component action="update" active="true" deletable="undefined" domain="rel" modifiable="undefined" objectid="7_EKLFRHG008K3502T2LOQD130K2" ordinal="200" type="control" uniquename="xu.test.popuptest" width="undefined">

<portletinstance action="update" domain="rel" objectid="5_EKLFRHG008K3502T2LOQD130K4" portletref="3_EKLFRHG008K3502T2LOQD13040"/>

</component>

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);

%>

      <h:form id="form1" styleClass="form">

            <br>

            <a href='<%=targetURLStr %>'target="_new">Link</a>

      </h:form>

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

BTW, many thanks to James Barnes.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值