Defines the sort order for the enclosing dsp:sort tag.

<dsp:orderBy property="sort-property" reverse="{true|false}"/>

Attributes

property

The property on which to sort. Two constraints apply:

reverse

After the item is sorted, determines whether to use the initial order (false) or reverse it (true). If you omit this attribute, the default is false.

Usage Notes

dsp:orderBy specifies the properties used to sort items in the dsp:sort-specified object. Multiple dsp:orderBy tags within the same dsp:sort tag specify multiple sort levels. For example, given a Collection of user profiles, you might sort first on the ages, and within each age, sort on last names, then first names.

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...