mmcglynn
mmcglynn

Reputation: 7662

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?

Upvotes: 1

Views: 143

Answers (1)

James
James

Reputation: 368

  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))

Upvotes: 3

Related Questions