16 May 2010

JSTL/JSP EL alternate Struts excercise solution

The De Post/PMC excercises (and the Struts blank sample application) are based on

  • Struts
    • tags-bean
    • tags-logic
    • tags-html
  • JSP scriptlets
In this post we will show how to move this to
  • Struts
    • tags-html
  • JSTL
  • JSP expression language
To enable JSTL/JSP/EL support in your application follow these instructions. Here’s the table from the excercise rendered with JSTL/JSP EL:
<c:forEach  var="product" items="${List}"  varStatus ="status">
  <tr class="${(status.index%2==1)?'odd':'even'}">
    <td>
      <html:link action="<%=modify%>" paramId="id" paramName="product" paramProperty="id">
        <html:img srcKey="icon.edit" altKey="icon.alt.edit" border="0"/>
      </html:link> 
    </td> 
    <td>
      <html:link action="<%=remove %>" paramId="id" paramName="product" paramProperty="id">
        <html:img srcKey="icon.trash" altKey="icon.alt.trash" border="0"/>
      </html:link>
    </td>
    <td> ${product.name}</td> 
    <td> ${product.description}</td>
  </tr>
</c:forEach>