留言板
User roles in velocity template
Hi all,
How can we get the current logged in user's role in velocity variables?
Role may be single or may be multiple for a user.
Any help is appreciated.
Thanks & Regards,
Ishan Sahore
How can we get the current logged in user's role in velocity variables?
Role may be single or may be multiple for a user.
Any help is appreciated.
Thanks & Regards,
Ishan Sahore
Hi Ishan
#set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
Now make a call to $roleLocalService.getUserRoles($userId)
HTH
#set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
Now make a call to $roleLocalService.getUserRoles($userId)
HTH
Harish Kumar:
Hi Ishan
#set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
Now make a call to $roleLocalService.getUserRoles($userId)
HTH
Hi Harish,
Thanks for your help.
Could you elaborate more, i.e. how to make a call to $roleLocalService.getUserRoles($userId) ?
I have to use this code in my portal_normal.vm file.
Based on the user's roles I have to show/hide the dockbar, etc.
Hi Ishan
It depends on your requirement. For example
In the above code, dockbar will be visible only to logged in user that belongs to specific user group.
HTH
It depends on your requirement. For example
#set ($hasUserGroupRole = $userLocalService.hasUserGroupUser($userGroup.getUserGroupId(),$user.getUserId()))
#if ($is_signed_in && $hasUserGroupRole))
#dockbar()
#end
In the above code, dockbar will be visible only to logged in user that belongs to specific user group.
HTH
Hi, i have the same problem.
I tried this code in my portal_normal.vm :
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id ))
#foreach( $usrRole in $usrRoles )
#If ($usrRole.getName() == "MyRole")
do something
#end
#end
But this works only if i log in the portal as Administrator, the variable $usrRoles is wholly empty if i log in as normal user or power user.
Where am i wrong?
Thanks a lot.
I tried this code in my portal_normal.vm :
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id ))
#foreach( $usrRole in $usrRoles )
#If ($usrRole.getName() == "MyRole")
do something
#end
#end
But this works only if i log in the portal as Administrator, the variable $usrRoles is wholly empty if i log in as normal user or power user.
Where am i wrong?
Thanks a lot.
Pinkesh Gandhi,修改在11 年前。
RE: User roles in velocity template
Junior Member 帖子: 99 加入日期: 12-1-27 最近的帖子
If you want to use the above solution into your webcontent template, then please make sure the following property set blank into your porta-ext.properties, otherwise you could not be able to use $serviceLocator in your velocity template.
#
# Input a comma delimited list of variables which are restricted from the
# context in Velocity based Journal templates.
#
journal.template.velocity.restricted.variables=