liferayliferay-6liferay-velocity

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


I am using the below code in ADT custom template code

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

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

Is there anything I'm missing here? but


Solution

  • The util class AssetEntryLocalServiceUtil is not accessible from a Freemarker template.

    What you're trying to do is to get access to AssetEntryLocalService. Access to Liferay services is restricted in ADT templates.

    You can get instance to AssetEntryLocalService through ServiceLocator, but you have to tell Liferay to allow it.

    Default configuration restricts access to serviceLocator variable (in 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
    

    The setting needs to be overridden to empty value in portal-ext.properties (ie. allow the usage of serviceLocator in templates).

    Then you can finally call serviceLocator.findService to get the service.

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