4.7.5. Freemarker context object: comparatorFactory

Purpose

Returns sort elements by the value of the specified property.

Table 4.45 All Methods

Modifier and Type

Method and Description

Comparator<org.jdom2.Element>

createElementComparator(String property)

Creates an ElementComparator which compares using property

@param property
        name of element to use for comparison
@return ElementComparator

Example of usage

<#assign labelAttributes = metafactory.findChildrenByProperty(currentModelObject, "attribute", "label")>
<#assign labelReferences = metafactory.findChildrenByProperty(currentModelObject, "reference", "label")>
<#assign all = labelAttributes + labelReferences>

<#--comparator sorts elements by value of the specified property-->
<#assign comparator = comparatorFactory.createElementComparator("label" )>
<#assign sortedItems = metafactory.sort(all, comparator)>
<#if sortedItems.size() == 0 >
        <#-- No properties found -->
<#else>
        <#-- Normal behaviour -->
</#if>