简体   繁体   中英

Why aren't Liferay objects rendering in my Velocity template?

A simple example:

/* Get user roles */
#set($userId=$request.attributes.get('USER_ID'))
#set($roleLocalService=$serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
$roleLocalService.getUserRoles($userId)

What renders on the page is just the text with no data.

$roleLocalService.getUserRoles($userId)

What am I missing?

  1. Be sure you're allowed to use serviceLocator . The default value in portal.properties is velocity.engine.restricted.variables=serviceLocator which means serviceLocator is not available to templates. Set it to "blank" (or at least do not include serviceLocator ). For example, set it to

velocity.engine.restricted.variables=

in a portal-ext.properties file inside the Liferay Home directory.

  1. $request.attributes.get is going to give you the String value of the userId. So you need to convert this to a Long using something like:

$roleLocalService.getUserRoles($getterUtil.getLong($userId))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM