How to sort array items in a user macro using velocity?

I want to displays members of a group, sortet by the displayName instead of the username.
Something like this:

{code}

#set($memberslist = $userAccessor.getMemberNamesAsList($group))

#set($myArrayList = [])
#foreach( $member in $memberslist )
  $myArrayList.add( {"fullname" : $action.getUserFullName($member) }) 
#end

#foreach( $item in  $sortTool.sort($myArrayList, "fullname:asc") )
   <li> $item.toString()
 #end

{code}

  

This does not work for me. Can you help me?

2 answers

Have you looked at this one: https://answers.atlassian.com/questions/218237/sort-list-of-objects-in-velocity

It helped me with my sorting issues :)

Sana,

many thanks. Sorry, I didn't reply to your hint.

Unfortunately that solution didn't work for me. I got an exception error.

So that request is still open (for me). Any idea (someone else)?

I have now a new similar task: I get the descendants of a given page in a user macro. I want to sort that pages by the last-modify-date. Again: how can that be done?

My user macro so far:

 

## Macro title: Page descendants
## Macro has a body: N
## List all descendant pages below a give page 
## Developed by: Stefan Baader
## Date created: 13/10/2015
## Installed by: Stefan Baader

## @param Page:title=Page|type=confluence-content|required=true|desc=Select a page do use

#set( $pages = $pageManager.getPage($space.key, $paramPage).getDescendants() )

Descendants of page "${paramPage}"

<table>
<tr>
<th>Seite</th>
<th style="white-space:nowrap;">Vers. Nr.</th>
<th style="white-space:nowrap;">Aktualisiert am</th>
</tr>
#foreach( $page in $pages) 
<tr>
<td>
<a href="$req.contextPath/pages/viewpage.action?pageId=$page.id">$page.title</a> 
</td>
<td>
$page.getVersion()
</td>
<td style="white-space:nowrap;">
$page.getLastModificationDate()  
</td>
</tr>
#end
</table>

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,799 views 26 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you