Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Stefan Baader
Contributor
April 22, 2014

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

0 votes
Stefan Baader
Contributor
October 12, 2015

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>
0 votes
SanaS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 11, 2014

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 :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events