After executing a query, the SearchFormHandler makes the search results available in two properties, which organize the same information differently:

For example, if you search for cuisine and recipe items in the food repository, the searchResults property contains items of type cuisine and recipe. The searchResultsByItem type property has a cuisine key whose value is a collection of cuisine items, and a recipe key called whose value is a collection of recipe items.

Within each collection, the items are in the order of their retrieval from the database. To sort the display order of items, use a servlet bean such as ForEach.

The following example uses ForEach to iterate over the searchResultsByItemType property, and display only the recipes returned by the search sorted by their display name:

<p>Your search returned the following products:</p>

<dsp:droplet name="ForEach">
 <dsp:param name="array" bean="CatalogSearch.searchResultsByItemType.recipe"/>
 <dsp:param name="sortProperties" value="+displayName"/>

 <dsp:oparam name="output">
   <li><dsp:valueof param="element.displayName">Unknown recipe</dsp:valueof>

 <dsp:oparam name="empty">
   <p>No matching recipes were found.
loading table of contents...