Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > sort
Added by digi9ten, last edited by Don Brown on Jan 06, 2007  (view change)
Please make sure you have read the test:Tag Syntax document and understand how tag attribute syntax works.

Description

NOTE: JSP-TAG

A Tag that sorts a List using a Comparator both passed in as the tag attribute. If 'id' attribute is specified, the sorted list will be placed into the PageContext attribute using the key specified by 'id'. The sorted list will ALWAYS be pushed into the stack and poped at the end of this tag.

Parameters

Name

Required

Default

Evaluated

Type

Description

comparator true true java.util.Comparator The comparator to use
source false true String The iterable source to sort

Examples

USAGE 1:
<s:sort comparator="myComparator" source="myList">
     <s:iterator>
     <!-- do something with each sorted elements -->
     <s:property value="..." />
     </s:iterator>
</s:sort>

USAGE 2:
<s:sort id="mySortedList" comparator="myComparator" source="myList" />

<%
   Iterator sortedIterator = (Iterator) pageContext.getAttribute("mySortedList");
   for (Iterator i = sortedIterator; i.hasNext(); ) {
     // do something with each of the sorted elements
   }
%>