Lifefay freemarker ADT: methods unavailable?

1.3k Views Asked by At

I'm trying to work on some ADT for asset publisher (Documents and Media type), but I often have a message telling me that :

Expression assetRenderer.getDataRepositoryId is undefined 

or

Expression assetRenderer.getFileEntryId is undefined

I found some threads where people said that we must add

velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=

in portal-ext.properties to get some more classes and variables available, but still I'm not able to call some methods and i don't know why.

I did a

${assetRenderer.getClassName()}

which returns: com.liferay.portlet.documentlibrary.model.DLFileEntry

So I should be able to use any DLFileEntry class public methods (and extended classes), right?

What do I miss?

1

There are 1 best solutions below

0
On BEST ANSWER

Asset renderer renders asset entries of the given class (ei. JournalArticle or DLFileEntry in your case). Asset renderer itself is not instance of the given class (in Java sense). It is always instance of com.liferay.portlet.asset.model.AssetRenderer.

To get instance of the related DLFileEntry, you must use DLFileEntryLocalService to find it.

<#-- Obtains instance of DLFileEntryLocalService -->
<#assign DLFileEntryLocalService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService") />

<#-- Function returning underlying DLFileEntry for the given AssetEntry -->
<#function getDLFileEntry assetEntry>
    <#return DLFileEntryLocalService.getDLFileEntry(assetEntry.getClassPK())/>
</#function>

Please note, that you need to enable the usage of serviceLocator explicitly by setting freemarker.engine.restricted.variables= in portal-ext.properties.