dsp:orderBy defines the sorting order for the enclosing dsp:sort tag. dsp:sort specifies the item with contents that need to be ordered and when the item is an object, dsp:ordeBy identifies the object property on which to base sorting. Multiple dsp:orderBy tags for a given dsp:sort can determine, primary, secondary, and tertiary sort order. It is possible, for example, to sort first on last name and, when there is a match in last name, use the first name for a secondary sort.

Attributes

ItemtoSorton:property(Required)

The property attribute holds the property to sort. The property identified here must be an object that is not a Dynamic Bean and it must be a property of the object specified in the parent dsp:sortvalues attribute.

SortingintheOppositeOrder:reverse

The reverse attribute determines, after the item is sorted, whether order should remain as is (false) or should be reversed (true). When omitted, the default, false, is used.

Example

<dsp:importbeantomap bean="AllStudents" var="students"/>
<dsp:sort var="sorter" values="${students}">
  <dsp:orderBy property="age" reverse="true"/>
  <dsp:orderBy property="lastName"/>

     <c:forEach var="forEach" begin="0" items="${sorter.sortedArray}">
        <li>Name: <c:out value="${students.lastName}"/>
     </c:forEach>
</dsp:sort>

In this example, the students are ordered first in reverse by age, and then as a secondary sort, they are ordered by last name. The eldest students are returned at the top of the list and those who have the same age are organized alphabetically by last name.

 
loading table of contents...