Foren

Velocity Liferay Services

thumbnail
Tom Mahy, geändert vor 12 Jahren.

Velocity Liferay Services

Regular Member Beiträge: 103 Beitrittsdatum: 11.05.11 Neueste Beiträge
Hi,

so im trying to call some services in my theme. My theme is a velocity theme.

inside navigation.vm i have :

#set($currentGroup = $layout.getGroup())
#set($currentGroupName = $currentGroup.getName())

$currentGroupName


and it shows the current group name, as it should.

now i have :

 #set($groupService = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
 #set($group = $groupService.getCompanyGroup($companyId))
$group


in the page it shows : $group and not the value.
no errors in the logs.

$groupService shows me : com.liferay.portal.service.GroupLocalServiceImpl@73345
So it seems that the class is loaded.

in my portal-ext.properties i have :
journal.template.velocity.restricted.variables=

what am i missing ?

i also followed : http://www.liferay.com/community/wiki/-/wiki/Main/Access+Liferay+Services+in+Velocity
but these examples do not work either.


Thank you.
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Velocity Liferay Services

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Can you just try
$groupService.getCompanyGroup($companyId).getName()

Regards,
Sandeep
thumbnail
Tom Mahy, geändert vor 12 Jahren.

RE: Velocity Liferay Services

Regular Member Beiträge: 103 Beitrittsdatum: 11.05.11 Neueste Beiträge
Hi,

i tried that but it doesnt work.
I only get the $group and not the value.

Thank you
thumbnail
Tejas Kanani, geändert vor 12 Jahren.

RE: Velocity Liferay Services (Antwort)

Liferay Master Beiträge: 654 Beitrittsdatum: 06.01.09 Neueste Beiträge
Hi Tom,

I've found the problem. Its companyId variable name.
As per init.vm it should be $company_id instead of $companyId

Please use $company_id and check. It worked for me.

Thanks,
Tejas
thumbnail
Tom Mahy, geändert vor 12 Jahren.

RE: Velocity Liferay Services

Regular Member Beiträge: 103 Beitrittsdatum: 11.05.11 Neueste Beiträge
Hi,

It works for me too now.
Documentation is wrong then : http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Journal+Template+%28Velocity%29

Can't believe i missed it. Thank you


Regards,
Tom Mahy
thumbnail
Tejas Kanani, geändert vor 12 Jahren.

RE: Velocity Liferay Services

Liferay Master Beiträge: 654 Beitrittsdatum: 06.01.09 Neueste Beiträge
Hi Tom,

Document which you were referring, is more emphasizing on Liferay v 5.
May be that could be the problem.

Looking at the source, the following variables being placed in the context, at least for 5.1.1. For technical details on the class type of each variable, see the method insertHelperUtilities(VelocityContext,String[]) in the class com.liferay.portal.velocity.VelocityVariables Additional variables are placed in the context by com.liferay.portlet.journal.util.JournalVmUtil.transform()

Please find below variables that could be accessed in Liferay 6.

Variables
  • request
  • portletConfig
  • renderRequest
  • renderResponse
  • xmlRequest
  • themeDisplay
  • company
  • user
  • realUser
  • layout
  • layouts
  • plid
  • layoutTypePortlet
  • scopeGroupId
  • permissionChecker
  • locale
  • timeZone
  • theme
  • colorScheme
  • portletDisplay
  • navItems
  • fullCssPath
  • fullTemplatesPath
  • init
  • portletGroupId
  • title
  • content
  • selectable
  • pageTitle
  • pageSubtitle


HelperUtilities
  • arrayUtil
  • auditMessageFactoryUtil
  • auditRouterUtil
  • browserSniffer
  • dateFormatFactory
  • dateTool
  • dateUtil
  • escapeTool
  • expandoColumnLocalService
  • expandoRowLocalService
  • expandoTableLocalService
  • expandoValueLocalService
  • getterUtil
  • htmlUtil
  • httpUtil
  • imageToken
  • iteratorTool
  • journalContentUtil
  • languageUtil
  • unicodeLanguageUtil
  • listTool
  • localeUtil
  • mathTool
  • numberTool
  • paramUtil
  • portalUtil
  • portal
  • prefsPropsUtil
  • propsUtil
  • portletURLFactory
  • velocityPortletPreferences
  • randomizer
  • saxReaderUtil
  • serviceLocator
  • sessionClicks
  • sortTool
  • staticFieldGetter
  • stringUtil
  • timeZoneUtil
  • utilLocator
  • unicodeFormatter
  • validator
  • accountPermission
  • commonPermission
  • groupPermission
  • layoutPermission
  • organizationPermission
  • passwordPolicyPermission
  • portalPermission
  • portletPermission
  • rolePermission
  • userGroupPermission
  • userPermission
  • dateFormats
  • locationPermission

Please correct me if i missed any.

And for some more ready to use variables, please refer init.vm

Thanks,
Tejas