IBM Support

How to create a link to a portlet (Standard API) that passes parameters to that portlet

Technote (FAQ)


Many times when developing an application, you want to create a link to a portlet and pass in some parameters. You might want to do this from a theme or from another portlet. How do you create such a link?


Setup procedures

To create a link in a theme or on a portlet to go directly to another page and portlet, perform the following steps:

1. Give a unique name to the page using either the XML Configuration Interface (XMLAccess) or the administrator portlet.

2. Give a unique name to the portlet on the page. You have to give a unique name to the portlet window or control on the page; simply giving a portlet a unique name in the Admin Portlet is not enough.

Note: The assigning of the unique name to the portlet on the page can only be done through XMLAccess.

Use XMLAccess to export the reference to the portlet on a page. Refer to the Sample Files in the XML Configuration Interface (XMLAccess) documentation found in the WebSphere Portal Information Center. You can also use the WebSphere Portal Admin portlets for managing pages to export the page, which will also contain the portlet window.

The XML Configuration Interface will generate a file similar to the one attached here:

3. Give the component that contains the portlet window a unique name such as shown below. (This is done by updating the text in the xml file.)

<component action="update" active="true" deletable="undefined" domain="rel" modifiable="undefined" objectid="7_3A7U7FH20OO9702T3BOU8700G2" ordinal="100" type="control" uniquename="" width="undefined">
<portletinstance action="update" domain="rel" objectid="5_3A7U7FH20OO9702T3BOU8700G6" portletref="3_3A7U7FH20OO9702T3BOU870002"/>

4. Then reimport this file either by using the command line XMLAccess interface or by using the import xml portlet within the WebSphere Portal Admin pages.

Creating a link from the theme

1. Make sure that your theme has this tag-lib already defined. These tags are only supported in the theme and should not be used in a portlet.

<%@ taglib uri=""
prefix="portal-navigation" %>

2. Add the following code:

< portal-navigation :urlGeneration contentNode=" p2psample.SearchResult " layoutNode=" "accessControlCheck="NoCheck">    
         < portal-navigation :urlParam name="myJSRParam" value="August" type="render" />
                   <a href="<% wpsURL.write(out); %>" class="wpsLinkBarLink">
               Call and pass the param now
      </ portal-navigation :urlGeneration>

Create a link from a portlet to a portlet

1. First decide if you want to use the URL generation helper classes or use the NavigationModel SPI directly.

2. Use the "Portal 6.0 Advanced URL Generation Helper classes"

3. Then add that jar to your portlets web-inf folder.

4. Add code like the following in your JSP

try {
HashMap map = new  HashMap();
  String[] value1 = { "testthis6" };
  map.put( " myJSRParam " , value1);

String url1 = PortletURLHelper.generateUrl( "p2psample.SearchResult" , "" , map, true , renderRequest, renderResponse);

%> The URL is .... <%= url1 %> < br >
< a   href =" <%= url1 %> " > url  to action and mode </ a >
} catch (Exception e)
%><%= e.getMessage() %>

5. If you decide to use the Navigation Model SPIs directly, then add the following code to your portlet or JSP:

private   PortletServiceHome psHome  = null ;
PortletStateManager mgr = null ;
if  ( psHome  == null  ){
Context ctx = new  InitialContext();
      psHome  = (PortletServiceHome) ctx.lookup( "portletservice/" );      }
try  {
PortletStateManagerService service = (PortletStateManagerService) psHome .getPortletService(PortletStateManagerService. class );
 mgr = service.getPortletStateManager(request, response);
} catch  (Exception ex) {
System. out .println( "the portlet service was unable to be retrieved" );
URLFactory urlFactory = mgr.getURLFactory();
boolean saveState = false;
HashMap params = new  HashMap();
String portletName = ""
  String[] value1 = { "testthis6" };
  map.put( " myJSRParam " , value1);
String finalUrl = "";
 try {
  final EngineURL url ;
  if(saveState) {
  url = urlFactory.newURL(Constants.SMART_COPY);
  } else {
  url = urlFactory.newURL(Constants.EMPTY_COPY);
  final selectionFactory = ( mgr.getAccessorFactory(;
  final SelectionAccessorController selectionCtrl = selectionFactory.getSelectionAccessorController(url.getState());
  selectionCtrl.setSelection( "p2psample.SearchResult" );
  if(portletName != null) {
    final PortletAccessorFactory portletAccessorFactory = (PortletAccessorFactory) mgr.getAccessorFactory(PortletAccessorFactory.class);
  final PortletAccessorController portletCtrl = portletAccessorFactory.getPortletAccessorController(portletName, url.getState());
  if(params != null) {
  // Dispose the accessor (avoids memory leak)
  finalUrl = url.writeDispose(new StringWriter()).toString();
 } finally {

Then the link will be like this sample:
   <a href="<%=finalUrl%>Link to portlet</a>

How to retrieve the parameters

In your called Portlet code to retrieve the parameter, add this in the doview method:

if(sessionBean != null) {
String passedParam = request.getParameter("myJSRParam");

Document information

More support for: WebSphere Portal
Application Development

Software version: 6.0, 6.1

Operating system(s): AIX, HP-UX, IBM i, Linux, Solaris, Windows, z/OS

Software edition: Enable, Express, Extend, Server

Reference #: 1322423

Modified date: 2015-02-26