在liferay主题(速度模板)中使用自定义服务或liferay服务? [英] Using custom services or liferay services in liferay themes (velocity templates)?
问题描述
如何在init_custom.vm
,portal_normal.vm
等速度文件中的liferay主题中使用自定义服务方法.
How to use custom services method in liferay themes in velocity files like init_custom.vm
, portal_normal.vm
etc.
我看到liferay为 GetterUtil
等github.com/liferay/liferay-portal/blob/master/portal-web/docroot/html/themes/_unstyled/templates/init.vm"rel =" nofollow> init.vm
文件.
I see liferay provides a lot of variables of helper utility classes like $portalUtil
for PortalUtil
, $getterUtil
for GetterUtil
and so on, inside the init.vm
file.
是否可以从UserLocalServiceImpl
获取我的自定义服务的实例,例如com.my.custom.service.MyCustomLocalServiceImpl
的实例还是liferay的服务?
So is it possible to get instance of my custom services like an instance of com.my.custom.service.MyCustomLocalServiceImpl
or services of liferay from UserLocalServiceImpl
?
以下是一些伪代码,以说明我需要什么:
Here is some psuedo code, to give an idea of what I need:
// 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))
环境:Liferay 6.1 CE GA1
Environment: Liferay 6.1 CE GA1
推荐答案
可能.
-
以下代码显示了如何获取服务:
The following code shows how to get the services:
// 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'))
然后只需调用服务方法:
Then simply call the service methods:
#set ($listOfItems = $myCustomLocalService.getAllItems())
#set ($listOfUsers = $userLocalService.getUsers(0, 99))
对于Liferay 6.1 CE GA1:我发现了此类 insertHelperUtilities
,
查看全文