views:

353

answers:

1

A list of books is displayed on the page. When a user clicks a book, its detail page is opened. Now the problem is that I need to encode each book's id with the detail page url.

The link to detail page is /loadDetailForm.do. If a book has id=23, the link should appear as /loadDetailForm.do?id=23.

I am pasting code here:

<logic:notEmpty name="BrowseForm" property="books">
       <logic:iterate id="book" property="books" name="BrowseForm" type="com.nms.bks.app1.domain.Book">
         <p><html:link action="/loadDetailForm" styleClass="btn_blue"><bean:write name="book" property="title"/></html:link></p>
       </logic:iterate>
      </logic:notEmpty>

Thanks

A: 

You can specify a map of parameters which the struts tag will append to the url.

See http://struts.apache.org/1.2.x/userGuide/struts-html.html#link

Look at the paramId, paramName and paramProperty attributes.

<html:link action="/loadDetailForm" 
       styleClass="btn_blue" 
       paramId="id" 
       paramName="book" 
       paramProperty="id">
          <bean:write name="book" property="title"/>
</html:link>

An alternative would be to use the JSTL tag library

<c:url value="expression" context="expression"
    var="name" scope="scope">
  <c:param name="param1" value="${thing.id}"/>
  ...
</c:url>

http://www.ibm.com/developerworks/java/library/j-jstl0318/

pjp
Accepted with no upvotes...
pjp