在liferay主题(速度模板)中使用自定义服务或liferay服务?

Pra*_*h K 3 service liferay liferay-theme liferay-velocity

如何使用自定义的服务方法,Liferay的主题,在速度文件一样init_custom.vm,portal_normal.vm等等.

我看到liferay在文件中提供了许多辅助实用程序类的变量,例如$portalUtilfor PortalUtil,$getterUtilfor GetterUtil等等init.vm.

那么有可能获得我的自定义服务的实例,com.my.custom.service.MyCustomLocalServiceImpl如liferay 的实例或服务UserLocalServiceImpl吗?

这是一些伪代码,用于了解我需要的内容:

// this code calls method from MyCustomLocalServiceImpl class to fetch items
#set ($listOfItems = $myCustomLocalServiceUtil.getAllItems())

// this code calls method from UserLocalServiceImpl class to fetch users
#set ($listOfUsers = $userLocalServiceUtil.getUsers(0, 99))
Run Code Online (Sandbox Code Playgroud)

环境:Liferay 6.1 CE GA1

Pra*_*h K 6

有可能的.

  1. 以下代码显示了如何获取服务:

    // Fetching instance of my custom services
    #set ($myCustomLocalService = $serviceLocator.findService('myCustomServices-portlet', 'com.my.custom.service.MyCustomLocalService'))
    
    // Fetching instance of UserLocalServiceImpl
    #set ($userLocalService = $serviceLocator.findService('com.liferay.portal.service.UserLocalService'))
    
    Run Code Online (Sandbox Code Playgroud)
  2. 然后简单地调用服务方法:

    #set ($listOfItems = $myCustomLocalService.getAllItems())
    
    #set ($listOfUsers = $userLocalService.getUsers(0, 99))
    
    Run Code Online (Sandbox Code Playgroud)

对于Liferay的6.1 CE GA1:我发现这个类VelocityVariablesImpl(见类似方法insertHelperUtilities,insertVariables),这实际上使得所有可用的速度模板的变量和辅助工具.