Skip to main content

How to create a link to target the action of a struts portlet

 Technote (FAQ)
 
Question
How can you create a link to target the action phase of a struts portlet? Many times your development will require you to create a link to a struts action either in JavaScript or from your theme. Because you do not have access to use the struts tags in those areas to create a valid WebSphere® Portal URL, this lack can cause some problems.
 
Answer
To create a link to an action phase, you can use one of the following three options:
  • Struts tag
  • Portlet tags
  • URL generation SPIs

Struts tag

You can use the Struts tag, as follows:


    <html:link action="/HelloAction">first 1</html:link>

This tag creates the full anchor tag for you. This option will work for most cases, but it is not usable as a variable or to be used in a JavaScript. This option can be used only in a portlet.


Portlet tags

Secondly, and the next preferred way, is to use the portlet tags themselves, as follows:

<portlet:actionURL var="testUrl">
<portlet:param name="spf_ActionName" value="spf_ActionListener" />
<portlet:param name="spf_strutsAction" value="!2fHelloAction.do" />
</portlet:actionURL>

<a href="<%=testUrl %>">Second 1</a>

One thing to note here is that !2f is the encoded slash ( / ) character. If your action has more slash characters, then each one needs to be encoded. This option can be used only in the portlet and is best when you want to have some JavaScript in your portlet to submit an action.



URL generation SPIs

The third option, which is more involved, is to use the URL generation SPIs. This option is best used in a theme. (You should use the second option of portlet tags when you need a URL in your portlet.) If you use the SPI helper classes, then you could use code such as the following.

<%
try{
HashMap map = new HashMap();
String[] value1 = {"spf_ActionListener"};
String[] value2 = {"!2fHelloAction.do"};
map.put("spf_ActionName", value1);
map.put("spf_strutsAction", value2);

String url1 = PortletURLHelper.generateUrl(ServletURLHelper.getCurrentPage(request,response), PortletURLHelper.getPortletWindowObjectId(renderRequest), map, renderRequest, renderResponse);

%>
<a href="<%=url1 %>">third 1 </a>
<%
}catch(Exception e)
{
%><%=e.getMessage()%>
<%
e.printStackTrace(System.out);
}
%>

To obtain the helper classes, go to "Portal 6.0 Advanced URL Generation Helper classes."

 
 
 

Copyright and trademark information

IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.

Rate this page

Please take a moment to complete this form to help us better serve you.

This material provides me with the information I need.






This material is clear and easy to understand.






Did the information help you to achieve your goal?

What updates, improvements, or related information would you like to see in this document?

Your response will be used to improve our document content. Requests for assistance, if applicable, should be submitted through your normal support channel as we cannot respond from this site.


Input the verification number to submit feedback:



Maintenance Window

Unscheduled Maintenance Window

There is no unscheduled maintenance scheduled at this time.

Document information

Product categories:

Software

Organizational Productivity, Portals & Collaboration

Portals

WebSphere Portal

Application Development


Operating system(s):

AIX, HP-UX, Linux, Solaris, Windows, i5/OS, z/OS


Software version:

6.0, 6.1


Software edition:

Enable, Express, Extend, Server


Reference #:

1317926


IBM Group:

Software Group


Modified date:

2008-09-18

Translate my page