Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
[CLOSED] How can I reference DLFile custom data in ADT?
Mirto Silvio Busico, modified 8 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
The thread continues at
https://web.liferay.com/community/forums/-/message_boards/message/82458841
I have the problem that I am not able to reference document type custom metadata fields.
In Content -> Documents and Media I have defined a new document type (eg MIO) with two metadata fields (eg MIOUsage and MIONotes).
In an asset publisher that displays only MIO document type I was able to define an ADT that displays Name, description and small image; but Iwas not able to reference the two custom fields.
I tried
which gives an "evaluated to null or missing" error
and
which gives the same error
How can I refer to metadata fields defined for a document type?
https://web.liferay.com/community/forums/-/message_boards/message/82458841
I have the problem that I am not able to reference document type custom metadata fields.
In Content -> Documents and Media I have defined a new document type (eg MIO) with two metadata fields (eg MIOUsage and MIONotes).
In an asset publisher that displays only MIO document type I was able to define an ADT that displays Name, description and small image; but Iwas not able to reference the two custom fields.
I tried
${assetRenderer.getMiousage()!"xxx"}
which gives an "evaluated to null or missing" error
and
${entry.getMiousage()!"xxx"}
which gives the same error
How can I refer to metadata fields defined for a document type?
Mirto Silvio Busico, modified 8 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
One step ahead.
Inserting this code in ADT
I can list the metadata thea are enabled in the Asset Publisher configuration
The document is a DLFile so I changed the thread title
Still I don't know how to reference the custom data.
Seems I have to use DLFileEntryLocalServiceUtil but I don't know how
Inserting this code in ADT
<#assign className = assetRenderer.getClassName()!"x" />
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
<#assign metaf = stringUtil.split(metadataFields) !"x" />
<#list metaf as metaf1>
${metaf1}
<!--#list-->
<!--#if-->
I can list the metadata thea are enabled in the Asset Publisher configuration
The document is a DLFile so I changed the thread title
Still I don't know how to reference the custom data.
Seems I have to use DLFileEntryLocalServiceUtil but I don't know how
Mirto Silvio Busico, modified 8 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
I've found an old article at http://platinumbed-liferay.blogspot.ch/2014/12/application-display-template-documents.html
I've put
in portal.properties. Then tried this code:
But I receive the error that serviceLocator is not found
Anyone knows how to manage this error?
I've put
freemarker.engine.restricted.variables=
in portal.properties. Then tried this code:
<#if entries?has_content>
<#list entries as curEntry>
${curEntry.getTitle(locale)}
<#assign dlFileEntryService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")>
<hr>
<!--#list-->
<!--#if-->
But I receive the error that serviceLocator is not found
The following has evaluated to null or missing:
==> serviceLocator [in template "20116#20160#66884" at line 5, column 31]
Anyone knows how to manage this error?
Mirto Silvio Busico, modified 8 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
A little step ahead.
Trying to follow the instructions at http://platinumbed-liferay.blogspot.it/2014/12/application-display-template-documents.html (that is for LR 6)
and https://web.liferay.com/it/community/forums/-/message_boards/message/73391506?_19_threadView=flat (to enable serviceLocator)
I came up with this adt:
This gives the error
on getFileEntryId
Any hint on how to convert the code in the blog to LR 7?
Trying to follow the instructions at http://platinumbed-liferay.blogspot.it/2014/12/application-display-template-documents.html (that is for LR 6)
and https://web.liferay.com/it/community/forums/-/message_boards/message/73391506?_19_threadView=flat (to enable serviceLocator)
I came up with this adt:
<#if entries?has_content>
<#list entries as entry>
<#assign curFileEntry = entry />
<#assign assetRenderer = curFileEntry.getAssetRenderer() />
<#assign className = assetRenderer.getClassName()!"x" />
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
<#assign dlFileEntryService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
${dlFileEntryService }<br>
<#assign xx = curFileEntry.getFileEntryId() >
<#assign dlFileEntry = dlFileEntryService.getFileEntry(xx)>
<!--#if-->
<!--#list-->
<!--#if-->
This gives the error
The following has evaluated to null or missing:
==> curFileEntry.getFileEntryId [in template "20116#20160#66884" at line 9, column 27]
on getFileEntryId
Any hint on how to convert the code in the blog to LR 7?
Mirto Silvio Busico, modified 8 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Another step ahead.
Now the problem is that entry.getExpandoBridge.getAttributeNames() returns an empty string
Here the code I used in the Asset Publisher ADT for a document type called "MIO" with two custom field: MIOUsage and MIONotes.
The code:
The result for an enty with all fields filled:
I tried to get field names and it returns an empty list.
I tried to access the fields with getAttribute using the field name or the field label: nothing is returned
How can I use getExpandoBridge.getAttributeNames() to get the attibute names?
Now the problem is that entry.getExpandoBridge.getAttributeNames() returns an empty string
Here the code I used in the Asset Publisher ADT for a document type called "MIO" with two custom field: MIOUsage and MIONotes.
The code:
<#if entries?has_content>
<#list entries as entry>
<#assign assetRenderer = entry.getAssetRenderer() />
<#assign entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale)) />
TITLE: ${entryTitle} <br>
<#assign className = assetRenderer.getClassName()!"x" />
CLASSNAME: ${className} <br>
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
<#assign myyy = entry.getExpandoBridge() />
EXPANDOBRIDGE: ${myyy.toString()} <br>
<#assign yyy = myyy.getAttributeNames() />
LIST ATTRIBUTES: ${yyy.toString() } <br>
<#list yyy>
<#items as y>
NAME ATTRIBUTE: ${y} <br>
<!--#items-->
<#else>
THERE ARE NO ATTRIBUTE NAMES <br>
<!--#list-->
<#assign xxx = myyy.getAttribute(" MIOUsage",false) !"FIELD NOT FOUND" />
EXPANDOBRIDGE: MIOUsage-fieldname value = ${xxx} <br>
<#assign xxxl = myyy.getAttribute(" Usage",false) !"FIELD NOT FOUND" />
EXPANDOBRIDGE: MIOUsage-label value = ${xxxl} <br>
<#else>
It is NOT a DLFileEntry
<!--#if-->
<hr>
<!--#list-->
<!--#if-->
The result for an enty with all fields filled:
TITLE: a_few_oh_sht_situations_640_27.jpg
CLASSNAME: com.liferay.document.library.kernel.model.DLFileEntry
EXPANDOBRIDGE: com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl@aa725
LIST ATTRIBUTES: java.util.Collections$3@3a4ee3aa
THERE ARE NO ATTRIBUTE NAMES
EXPANDOBRIDGE: MIOUsage-fieldname value = FIELD NOT FOUND
EXPANDOBRIDGE: MIOUsage-label value = FIELD NOT FOUND
I tried to get field names and it returns an empty list.
I tried to access the fields with getAttribute using the field name or the field label: nothing is returned
How can I use getExpandoBridge.getAttributeNames() to get the attibute names?
<#list entries as entry>
<#assign
entry = entry
assetRenderer = entry.getAssetRenderer()
entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale))
viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, assetRenderer, entry, !stringUtil.equals(assetLinkBehavior, "showFullContent"))
className = assetRenderer.getClassName()!"x"
dlFileEntryId = assetRenderer.getClassPK()
fileEntry = DLAppLocalServiceUtil.getFileEntry(dlFileEntryId)
fileVersion = fileEntry.getLatestFileVersion()
/>
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
${fileEntry.getExpandoBridge().getAttribute("nametext")}<br/>
</#if>
</#list>
<#assign
entry = entry
assetRenderer = entry.getAssetRenderer()
entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale))
viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, assetRenderer, entry, !stringUtil.equals(assetLinkBehavior, "showFullContent"))
className = assetRenderer.getClassName()!"x"
dlFileEntryId = assetRenderer.getClassPK()
fileEntry = DLAppLocalServiceUtil.getFileEntry(dlFileEntryId)
fileVersion = fileEntry.getLatestFileVersion()
/>
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
${fileEntry.getExpandoBridge().getAttribute("nametext")}<br/>
</#if>
</#list>
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™