liferay - 如何获得Liferay主题中的角色?

标签 liferay liferay-6 liferay-theme liferay-velocity

如何获取Liferay主题中登录用户的角色?如何检查用户是否属于特定角色?

最佳答案

UserLocalServicehasRoleUser 方法,可用于查找用户是否属于特定角色。 下面的代码可以放在templates文件夹下的navigation.vm文件中。

#set($UserLocalServiceUtil = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#if ($UserLocalServiceUtil.hasRoleUser(roleID, $user.getUserId())) // It takes roleID as input to check.
  //Proceed with whatever you want to 
#else
  //Proceed with something else

注意:如果您使用com.liferay.portal.service.UserLocalServiceUtil,而不是com.liferay.portal.service.UserLocalService , 正如在一些资源中可以找到的那样 this那么你会遇到以下异常,

ERROR com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No
  bean named 'com.liferay.portal.service.UserLocalServiceUtil' is defined
  com.liferay.portal.kernel.bean.BeanLocatorException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.liferay.portal.servi
ce.UserLocalServiceUtil' is defined

另一种方法是,

#set($role=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
$role.getUserRoles($user_id)

关于liferay - 如何获得Liferay主题中的角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17402816/

相关文章:

liferay - 可实例化的 portlet 和实例 ID

在 liferay 中上传大量文档文件时,Linux 服务器的内存不会释放

java - Liferay 7 - 在 Authenticator 类中设置共享 session 属性

liferay - 如何知道网站管理员和网站所有者拥有哪些权限?

dockbar liferay 6.2 的 css 更改

java - Liferay 导航 Hook

liferay - 自定义门户的导航栏

java - 如何在 Liferay serveResource(-, -) 方法中从 AJAX 请求下载文件

java - 在 session 中保存 - Liferay Portlet

java - 在 liferay 中使用 Spring MVC 和 Maven 自定义 Taglib?