Unable to get the logged user screen name in velocity template - DXP?

Chanakya P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Hi All,

I used below code in velocity template (Structures and Template) to get the logged user screenName
    #set( $user = $permissionChecker.getUser()) 
    Screen Name: $user.screenName<br>

Above code always giving test user related screenName eventhough logged with other user.

Actuall Result:
    Always showing test user screen name eventhough logged with other user.


Expected Result:
    It should show the user screen name who is logged in to the portal.
    
Can any help me out.

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

First, shame on your for continuing to use Velocity instead of Freemarker. Now that we have that out of the way :) ...

 

1. What if you use another mechanism to get the user? for example, if you use the staticUtil to load the PortalUtil class and get the user from the Request -- does it still give you the same result?

2. Can you share your velocity template with me. I will (reluctantly) add it to a local DXP on my side and try it, if #1 doesn't give you a better result.

 

(Can you also share the exact version SP/FP you are running)

 

Chanakya P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Thank you for reply.

 

Version: liferay-dxp-digital-enterprise-7.0-sp6

 

Structure: just have one text field and am not used this text filed in template.

Template Code:

#set( $user = $permissionChecker.getUser()) 
Screen Name: $user.screenName<br> 

thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Chanakya P:

Template Code:

#set( $user = $permissionChecker.getUser()) 
Screen Name: $user.screenName<br> 

In the template editor, under "Details", there's a "Cachable" checkbox, checked by default. The help text reads:

Only uncheck when developing templates which use request handling, CMS query API, or other dynamic features.

Uncheck this, because you're using dynamic features. Otherwise it will always show the (cached) value from its first execution.

Chanakya P, modified 2 Years ago. Junior Member Posts: 72 Join Date: 2/17/14 Recent Posts

Thanks for your solution.

It is working now yes