1

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?

mmcglynn
  • 7,668
  • 16
  • 52
  • 76

1 Answers1

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

James
  • 368
  • 2
  • 3