views:

780

answers:

1

Hello,

I am using strus2 tags in a jsp to iterate over a collection:

<s:if test="parent.entries.size > 0">
     <table border="3">
      <s:iterator value="parent.entries">
       <tr />
        <td><s:property value="entry"></td>
        <td><s:property value="date" ></td>
          </tr>
      </s:iterator>
     </table>
</s:if>

I am having trouble sorting the result by examining the time stamp (date/time) provided by the second column (date). The underlying action is exposing mySet, which is unsorted and the timestamp value for the second column is automatically generated for every new insert.

The objective is to simply sort the rows with the last record on top. I am not executing an explicit select statement on the database, rather than the parent entity of mySet is retrieved.

Is there a recommended way to sort this collection on the jsp (action result) level using struts2 tags and the timestamp value?

Thanks for any advice. Kind regards

+1  A: 

If you are using struts 2 probably you want to take a look to the display tag, with this tag your table will look something like this:

<display:table defaultsort="1" id="yourListIdentifier" name="yourListIdentifier" pagesize="10" requestURI="/yourAction" sort="list">
    <display:column property="entry" title="entry"/>
    <display:column property="date" title="date" sortable="true" defaultorder="ascending"/>
</display:table>

And another way of doing it is that you could probably code some javascript that sort the table on the client side.

Hope this helps.

chermosillo
Thanks, but looks like the struts tag s:property is gone, will the display tag retrieve the list right out from the action?
denchr
probably I miss this up, the name on the display:table should be a reference to the object used as source for the table, and the requestURI is the action to sort, exports, and paging, so if your page is served under /yourAction.do , you should have requestURI="/yourAction.do"
chermosillo