Forums

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

How can I use #usernameLink() inside a servlet

Alexander Bien
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 9, 2018

Hello,

i created a macro plugin with a list of all spaces and their administrators. To display information about the administrators i used the #usernameLink() function inside the velocity template of my macro.

That worked fine so far but because we did not want any user to have access to that macro, we decided to create a servlet instead. I render the velocity template inside the doGet() method of the servlet:

renderer.render("templates/spaces-list-template.vm", velocityContext, resp.getWriter());

 The velocity template looks like this:

<html>
<head>
<title>Bereichsliste</title>
<meta name="decorator" content="atl.admin" />
$webResourceManager.requireResource("de.it.confl.confluence-spaces-list:confluence-spaces-list-resources")
</head>
<body>
<table class="aui">
    <thead>
        <tr>
            <th>Bereich</th>
            <th>Koordinierende</th>
        </tr>
    </thead>
    <tbody>
        #foreach($spaceData in $spacesData)
        <tr>
            <td><a href="/confluence/display/$spaceData.key" title="$spaceData.name">$spaceData.name</a></td>
            <td>
                #foreach($admin in $spaceData.admins)
                    #if($velocityCount > 1)
                        ,
                    #end
                    #usernameLink($admin)
                #end
            </td>
        </tr>
        #end
    </tbody>
</table>
</body>
</html>

 As a result, i get this:

Unbenannt.PNG

How can i get the #usernameLink() function to render properly?

 

Thank you.

 

 

 

 

1 answer

1 accepted

1 vote
Answer accepted
Stephen Deutsch
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.
February 14, 2018

Hello Alexander,

It's possible that the #usernameLink macro isn't available in your context. I found the source for #usernameLink in \confluence\webapp\template\includes\macros-deprecated.vm:

#*
Link to a user, given their username. If the username doesn't exist, "Anonymous" is printed
deprecated since 5.2
*#
#macro (usernameLink $username)
#trim()
#if ("$!username" != "")
#if ($action.getUserFullName($username))
<a href="#userLinkUrl($!req.contextPath, $username)"
#if($permissionHelper.canView($action.authenticatedUser, $action.getUserByName($username)))
class="url fn confluence-userlink" data-username="$generalUtil.htmlEncode($username)"
#else
class="url fn"
#end
>$generalUtil.htmlEncode($action.getUserFullName($username))</a>
#else
<a href="#userLinkUrl($!req.contextPath, $username)">$username</a>
#end
#else
$action.getText('anonymous.name')
#end
#end

Maybe you could just include that in your .vm file.

Alexander Bien
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 16, 2018

Hello Stephen,

that works! Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events