utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") 未定义

utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") is undefined

我在 ADT 自定义模板代码中使用以下代码

<#assign storageEngineUtil = utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") />

但这给了 utilLocator.findUtil("com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil") is undefined

这里有什么我遗漏的吗? 但是

实用程序 class AssetEntryLocalServiceUtil 无法从 Freemarker 模板访问。

您想要做的是访问 AssetEntryLocalService。访问 Liferay 服务在 ADT 模板中受到限制。

您可以通过 ServiceLocator 获取到 AssetEntryLocalService 的实例,但您必须告诉 Liferay 允许它。

默认配置限制访问 serviceLocator 变量(在 portal.properties 中)。

#
# Set a comma delimited list of variables the FreeMarker engine cannot
# have access to. This will affect Dynamic Data List templates, Journal
# templates, and Portlet Display templates.
#
freemarker.engine.restricted.variables=serviceLocator

需要在 portal-ext.properties 中将设置覆盖为空值(即允许在模板中使用 serviceLocator)。

然后你终于可以调用serviceLocator.findService来获取服务了。

<#assign assetEntryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService") />