Extensions Wiki » Extensions » Sort a list of XWiki objects

Changes for document Sort a list of XWiki objects

Last modified by Vincent Massol on 2012/11/12 16:28
From version 2.1
edited by Vincent Massol
on 2012/11/12 16:13
To version 3.1
edited by Eduard Moraru
on 2012/11/12 16:23
Change comment: There is no comment for this version

Metadata changes

Document author
xwiki:XWiki.VincentMygmassol

Object changes

Object number 0 of type ExtensionCode.ExtensionClass modified

Description
... ... @@ -1,10 +1,15 @@
1 +The problem with directly using $sorttool.sort(...) on a list of XWiki objects is that $sorttool expects the objects to have getters for the properties you want to sort on. However, XWiki objects don`t work that way and, instead, you have to do $object.getProperty(propertyname).value ge the actual property value.
2 +
3 +To work around this problem, you can use the velocity macro below which supports sorting by a property name and allows multiple values for the sorted property.
4 +
5 +== Macro ==
1 1 {{code language='velocity'}}
2 2 {{velocity output='false'}}
3 3 #*
4 4 * Sort a list of XWiki objects using an property as comparator.
5 5 *
6 - * @param inputObjects the list of XWiki objects to sort
7 - * @param propertyName the name of the XWiki object property to sort the inputObjects by
11 + * @param inputObjects the list of XWiki objects to sort.
12 + * @param propertyName the name of the XWiki object property to sort the inputObjects by. Multiple values for the same property are allowed.
8 8 * @param outputObjects the list where to append the sorted objects. This list must not be null and should be empty before calling the macro.
9 9 *#
10 10 #macro (sortXWikiObjectsList $inputObjects $propertyName $outputObjects)

Download XWiki

Get Connected