I wish every tag was a s:tag.

By Jason Pyeron, Principal Consultant at PD Inc. December 16, 2010

We are using the displaytag in our struts2 application, but we have come across difficulties with action prefixes in the pattern of foo!bar.

Quoting: [1]

How do I use this tag with Struts? The links that it creates for sorts and exports all point back to the JSP page, not my Action!

Use the requestURI attribute of the column tag. When the requestURI attribute is present, links for sorting, exports, and paging are formed by adding any tag generated parameters to the value of requestURI attribute. So if your page is served under /ManageLatin.do , you should have requestURI="/ManageLatin.do" on your display:table.

Using the requestURI attribute with an empty "" attribute is another strategy. Sometimes you don't know what the uri is because the table might be part of an included tile. The resulting URL will be a link that is based upon the original requestURI + the appended display tag parameters.

I have to beg to differ with this answer.

The first issue I have is that it is a static encoding of data to provide control of the application. It is always an anti-pattern to hard code references to self, because when it is copied for use elsewhere the other will point back to the original source.

Next it is limiting the code to a single use. If there were to be a change in url, then a new JSP would be needed.

<s:url var="url" escapeAmp="false"/>
	     
<display:table 
 requestURI='<%=((String)request.getAttribute("url"))%>' 
 id="itemList" name="itemList" 
 class="tablesorter" sort="list" pagesize="25">

Note the requestUri is now populated from the struts value stack's "#url" entry. Lastly, the url tag creates a reference [2] to the proper action by default. Now this code will refer to the calling action regardless of where the JSP was included from or by (ex tiles, or decorators, or chained actions).

Citations

  1. http://displaytag.sourceforge.net/10/faq.html#action
  2. http://stackoverflow.com/questions/700720/creating-navigation-links-in-struts-2