为什么Liferay对象不能在我的Velocity模板中渲染?
问题描述:
一个简单的例子:为什么Liferay对象不能在我的Velocity模板中渲染?
/* Get user roles */
#set($userId=$request.attributes.get('USER_ID'))
#set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
$roleLocalService.getUserRoles($userId)
在页面上呈现什么只是没有数据的文本。
$ roleLocalService.getUserRoles($用户id)
我缺少什么?
答
- 请确保您允许使用
serviceLocator
。portal.properties
中的default value为velocity.engine.restricted.variables=serviceLocator
,这意味着serviceLocator
不适用于模板。将其设置为“空白”(或至少不包括serviceLocator
)。例如,在一个portal-ext.properties
文件Liferay的主目录内将其设置为
velocity.engine.restricted.variables=
。
-
$request.attributes.get
将为您提供userId的字符串值。所以,你需要将其转换为长期使用的东西,如:
$roleLocalService.getUserRoles($getterUtil.getLong($userId))