« Return to Thread: Struts 2 / DisplayTag example

Struts 2 / DisplayTag example

by kenk :: Rate this Message:

| View in Thread

Everyone,

I've had a hard time getting DisplayTag and Struts 2 to play nicely together.  I've finally achieved success, and I wanted to post this example to the community, primarily because I've found information on these two hard to find.

This example displays a list of test scenarios:  

<display:table name="${scenarioList}"  class="its" uid="row" pagesize="20" sort="list" requestURI="" >
  <display:column title="" >
    <s:hidden name="scenarioList[%{#attr.row_rowNum - 1}].scenarioId" value="%{#attr.row.scenarioId}"/>
    <s:checkbox name="select[%{#attr.row_rowNum - 1}]" value="select[%{#attr.row_rowNum - 1}]" />
  </display:column>
  <display:column property="number" sortable="true" href="testScenario2.jsp" paramId="id" paramProperty="scenarioId" />
  <display:column property="description" sortable="true"  />
  <display:column property="standard" sortable="true"  />
</display:table>

I've defined scenarioList (java.util.List) on my Struts action.  I did not need to use the <s:set> tag as seen in other posts.  I'm using "uid" instead of "id" because the displaytag docs says I need to.  I'm paging and sorting successfully -- the requestURI setting seems to have a lot to do with that.

The first column of my table displays a checkbox (the idea here is to allow user selection of multiple rows).  The OGNL syntax took me a long time to figure out, the "[]" mean an index, %{} contains an OGNL expression, #attr means look at the page context, row_rowNum is pure DisplayTag for the row number (based on uid), and -1 is needed to get DisplayTag to start at 0 rather than 1.

Hope this info helps someone -- K

 « Return to Thread: Struts 2 / DisplayTag example