The velocity version won't work because the sort function is not
available.. Apparently Groovy does the magic..
I've added a sort() function to the xwiki API for the future.. In the
meantime you can use groovy
Ludovic
Ludovic Dubost wrote:
Hi,
It should work both in groovy and velocity using the list.sort()
function and xwiki.getArrayList() and xwiki.getHashMap() functions
Something like
<%
catdoc = xwiki.getDocument("Blog.Categories")
list = xwiki.getArrayList()
map = xwiki.getHashMap()
for(cat in catdoc.getObjects("Blog.Categories")) {
name = catdoc.display("name", cat)
list.add(name)
map.put(name, cat)
}
for(item in list.sort()) {
cat = map.get(item)
desc = catdoc.display("description", cat)
println "* $item : $desc"
}
%>
#set($catdoc = $xwiki.getDocument("Blog.Categories"))
#set($list = $xwiki.getArrayList())
#set($map = $xwiki.getHashMap())
#foreach($cat in $catdoc.getObjects("Blog.Categories"))
#set($name = $catdoc.display("name", $cat))
#set($ok = $list.add($name))
$map.put($name, $cat)
#end
#foreach($item in $list.sort())
#set($cat = $map.get($item))
#set($desc = $catdoc.display("description", $cat))
* $item : $desc"
#end
Ludovic
lauzon(a)us.ibm.com wrote:
I have a page with a number of objects, which I
want to display in
sorted order. I currently have code which can view all the items (the
page as well as the class is "Main.Teams":
#set($teamsdoc = $xwiki.getDocument("Main.Teams"))
#foreach($team in $teamsdoc.getObjects("Main.Teams"))
* $team.get('name')
#end
I allow users to add new teams, but they always go to the bottom of
the list. However I'd like to print out them in order by the "name"
property. I've tried using groovy for this, but I just can't get
simple things (like printing list contents any way other than "print
teams") to work. Can anyone help? Thanks ...
shawn.
------------------------------------------------------------------------
--
You receive this message as a subscriber of the
xwiki-users(a)objectweb.org mailing list.
To unsubscribe: mailto:xwiki-users-unsubscribe@objectweb.org
For general help: mailto:sympa@objectweb.org?subject=help
ObjectWeb mailing lists service home page:
http://www.objectweb.org/wws
------------------------------------------------------------------------
--
You receive this message as a subscriber of the xwiki-users(a)objectweb.org mailing list.
To unsubscribe: mailto:xwiki-users-unsubscribe@objectweb.org
For general help: mailto:sympa@objectweb.org?subject=help
ObjectWeb mailing lists service home page:
http://www.objectweb.org/wws