Wednesday, December 19, 2012

Servidce/Util classes access in template (.vm) file in Liferay

Hi Developers,

Many times you need to access services/util class in template. 

Below is some importance hits for the same.

=> Access services using findService method in Velocity(vm)

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
=>Access util class using  findUtil Method for inbuilt Util of Liferay
#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))
=> some times you also need to access util class which is not have access in template file like StorageEngineUtil. for that you can use below approch..

#set ($util = $portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance()) 


HTH.. :))

No comments:

Post a Comment