Sortedset (value of collection)

From JRapid

(Redirected from Sortedset)
Jump to: navigation, search

A sortedset is a set which comes ordered from the database. The "sortedset" attribute is a posible value for the collection attribute of a property. This doesn't mean that it is ordered in the database, moreover a java.util.Set doesn't imply order.

The order in which a sortedset is sorted can specified by the sortexpr attribute if the property is embedded or the sort attribute if it is not.

Usage

       <property ... collection="sortedset" label="Image" name=NAME ... />

Extra attributes:

  • sortexpr = EL : Variables that can be used in the expression are 'now', 'userId' and 'obj', which refers to the object that must be sorted.
  • sort = COMPARATOR_CLASS | natural : a java.util.Comparator class or the "natural" value.

Example

  • If the property is embedded you can use the sortexpr attribute to sort the collection:

In this example the collection of images of a product is being sorted by the image property "description".

<entity label="Product" menu="Products" name="Product">
            ...
            <property childproperty="product" collection="sortedset" embedded="inline"
            entity="ProductImage" extendable="extendable" height="100" label="Image" labelposition="top"
            name="image" sortexpr="obj.description" width="100"/>
            ...
</entity>
  • If the property is not embedded you can use the sort attribute to sort the collection:

In this example we created a class "ImageComparator.java" which implements the java.util.Comparator interface to sort the collection of "images" of a "Product".

 
<entity label="Product" menu="Products" name="Product">
     ...
     <property collection="sortedset" entity="ProductImage" extendable="extendable" height="100"
     label="Image" labelposition="top" name="image" sort="com.minicrm.sort.ImageComparator" width="100"/>
     ...
</entity>

See also

sortable

Personal tools