Here are the steps to access services and util class of custom portlet in velocity template.
1) Make sure the services and util class which you want to access are available inside tomcat/lib/ext.
2) In order to access services you need to place below property inside portal-ext.
Which means you wont be able to access serviceLocator inside velocity template.
So make sure before you access any service inside velocity template change this property to
3) Access services using findService Method of Custom Portlet in Velocity.
4) Access Liferay Services using findService Method in Velocity
5) Access util class using findUtil Method for inbuilt Util of Liferay
6) Access util Class of Custom Portlet in Velocity refer below link
http://www.liferay.com/web/raymond.auge/blog/-/blogs/2245146
1) Make sure the services and util class which you want to access are available inside tomcat/lib/ext.
2) In order to access services you need to place below property inside portal-ext.
journal.template.velocity.restricted.variables=By default this property will be like this
journal.template.velocity.restricted.variables=serviceLocator
Which means you wont be able to access serviceLocator inside velocity template.
So make sure before you access any service inside velocity template change this property to
journal.template.velocity.restricted.variables=
3) Access services using findService Method of Custom Portlet in Velocity.
#set ($customLocalService = $serviceLocator.findService('my-profile-portlet', 'com.sample.portlet.myprofile.service.MyProfileDataLocalService'))
#set ($number=$customLocalService.getMyProfileDatasCount())
$number
Normally we use findService(serviceName) method to access Liferay service.
But to access custom portlet service we have to use findService(contextName,ServiceName).
findService(serviceName) will search at the portal level and findService(servletContextName , serviceName) will search at specified portlet level.
But to access custom portlet service we have to use findService(contextName,ServiceName).
findService(serviceName) will search at the portal level and findService(servletContextName , serviceName) will search at specified portlet level.
4) Access Liferay Services using findService Method in Velocity
#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id")))
#set ($emailAddress = $user.getEmailAddress())
5) Access util class using findUtil Method for inbuilt Util of Liferay
#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))
6) Access util Class of Custom Portlet in Velocity refer below link
http://www.liferay.com/web/raymond.auge/blog/-/blogs/2245146