Forums de discussion
Can't fetch documents with freemarker on templates
Yannis Sinadinos, modifié il y a 6 années.
Can't fetch documents with freemarker on templates
Junior Member Publications: 39 Date d'inscription: 20/03/17 Publications récentes
Hi,
I created a structure which contains documents and also created the related template.
In the template I added freemarker code to fetch the documents these but is not working.
My code is
and the error
In order to use statitUtil I went to Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables.
and i deleted staticUtil and all the restricted Variables and classes. But no luck... Still getting this error...
Any ideas?
I created a structure which contains documents and also created the related template.
In the template I added freemarker code to fetch the documents these but is not working.
My code is
<#assign fileEntry = staticUtil["com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil"]>
<#assign file = fileEntry.getFileEntryByUuidAndGroupId(uuId,groupId)>
and the error
09:16:07,089 ERROR [http-nio-8080-exec-9][runtime:60] Error executing FreeMarker template
FreeMarker template error:
No error description was specified for this error; low-level message: java.lang.ClassNotFoundException: com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil cannot be found by com.liferay.portal.template.freemarker_2.0.24
----
FTL stack trace ("~" means nesting-related):
- Failed at: #assign fileEntry = staticUtil["com.l... [in template "20116#20152#45193" at line 26, column 5]
----
Java stack trace (for programmers):
----
freemarker.template.TemplateModelException: [... Exception message was already printed; see it above ...]
at freemarker.ext.beans.ClassBasedModelFactory.get(ClassBasedModelFactory.java:52)
at freemarker.core.DynamicKeyName.dealWithStringKey(DynamicKeyName.java:145)
at freemarker.core.DynamicKeyName._eval(DynamicKeyName.java:73)
at freemarker.core.Expression.eval(Expression.java:78)
at freemarker.core.Assignment.accept(Assignment.java:131)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)....
In order to use statitUtil I went to Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables.
and i deleted staticUtil and all the restricted Variables and classes. But no luck... Still getting this error...
Any ideas?
Yannis Sinadinos, modifié il y a 6 années.
RE: Can't fetch documents with freemarker on templates
Junior Member Publications: 39 Date d'inscription: 20/03/17 Publications récentes
I also created the cfg file in bundle/osgi/config as mentioned here but still no luck...
Even when setting "restrictedVariables = " I still get the same error or my portal faces Internal server error 500 and I have to recove it by deleting the related entries in configuration_ table. Check this issue for more details.
I am using Liferay 7.0 GA4
Even when setting "restrictedVariables = " I still get the same error or my portal faces Internal server error 500 and I have to recove it by deleting the related entries in configuration_ table. Check this issue for more details.
I am using Liferay 7.0 GA4
Massimo Bevilacqua, modifié il y a 6 années.
RE: Can't fetch documents with freemarker on templates (Réponse)
Regular Member Publications: 210 Date d'inscription: 27/12/16 Publications récentes
Instead of staticUtil try serviceLocator
I never used a config file inside bundle/osgi/config, I added these lines in my portal-ext.properties
<#assign dlFileEntryService = serviceLocator.findService('com.liferay.document.library.kernel.service.DLFileEntryService') />
<#assign file = dlFileEntryService.getFileEntryByUuidAndGroupId(uuId,groupId) >
I never used a config file inside bundle/osgi/config, I added these lines in my portal-ext.properties
freemarker.engine.restricted.classes=
freemarker.engine.restricted.packages=
freemarker.engine.restricted.variables=
Yannis Sinadinos, modifié il y a 6 années.
RE: Can't fetch documents with freemarker on templates
Junior Member Publications: 39 Date d'inscription: 20/03/17 Publications récentes
It worked with serviceLocator. Still can't understand why staticUtil is not working.
Thank you Massimo for the quick reply.
Thank you Massimo for the quick reply.
Massimo Bevilacqua, modifié il y a 6 années.
RE: Can't fetch documents with freemarker on templates
Regular Member Publications: 210 Date d'inscription: 27/12/16 Publications récentes
StaticUtil works,
for example if I insert this code it works.
I have a "class not found" error , it seems it is not able to found the class DLFileEntryLocalServiceUtil
for example if I insert this code it works.
<#assign serviceContextThreadLocal = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"] />
I have a "class not found" error , it seems it is not able to found the class DLFileEntryLocalServiceUtil
Yannis Sinadinos, modifié il y a 6 années.
RE: Can't fetch documents with freemarker on templates
Junior Member Publications: 39 Date d'inscription: 20/03/17 Publications récentes
DLFileEntryLocalServiceUtil exists here:
https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/document/library/kernel/service/DLFileEntryLocalServiceUtil.html
Strange behaviour of StaticUtils or we are missing something.
https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/document/library/kernel/service/DLFileEntryLocalServiceUtil.html
Strange behaviour of StaticUtils or we are missing something.
Lee Jordan, modifié il y a 4 années.
RE: Can't fetch documents with freemarker on templates
Expert Publications: 449 Date d'inscription: 26/05/15 Publications récentes
If anyone at Liferay can offer the community guidance here, this is a real pain point for a lot of template developers.
chinmay abhyankar, modifié il y a 3 années.
RE: Can't fetch documents with freemarker on templates
New Member Publications: 3 Date d'inscription: 24/07/20 Publications récentes
<#list attachmentURL.getData()?split("/") as x> <#if x?counter ==3>
<#assign groupId = x?number>
</#if>
<#if x?counter ==6>
<#assign uuId = x?keep_before("?")>
</#if>
</#list><#assign dlFileEntry = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
<#if (uuId??) && (groupId??)>
<#assign file = dlFileEntry.getFileEntryByUuidAndGroupId(uuId,groupId) > ${file.getSize()/1000000} <#--will return file size in MB-->
</#if>
<#assign groupId = x?number>
</#if>
<#if x?counter ==6>
<#assign uuId = x?keep_before("?")>
</#if>
</#list><#assign dlFileEntry = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
<#if (uuId??) && (groupId??)>
<#assign file = dlFileEntry.getFileEntryByUuidAndGroupId(uuId,groupId) > ${file.getSize()/1000000} <#--will return file size in MB-->
</#if>