2

Hi fellow Liferay'ers,

I'm trying to get the categories of a journalArticle with a Freemarker template.

I tried this code:

<#assign journalArticleId = .vars['reserved-article-id'].data>
<#assign journalArticleResourceLocalServiceUtil = staticUtil["com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil"]>
<#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil"]>

<#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId, journalArticleId)/>
<#assign categoryList=assetCategoryLocalServiceUtil.getCategories("com.liferay.portlet.journal.model.JournalArticle",articleResourcePK) >

<#list categoryList as categoryList>
${categoryList.getName()}
</#list>

I also added This lines to the portal-setup-wizzard.properties

freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
freemarker.engine.restricted.packages=

When i execute the code it throws this error:

08:26:30,582 ERROR [http-nio-8080-exec-10][runtime:60] Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> staticUtil  [in template "20202#20246#41671" at line 14, column 51]

----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----

----
FTL stack trace ("~" means nesting-related):
        - Failed at: #assign journalArticleResourceLocalSe...  [in template "20202#20246#41671" at line 14, column 1]
----

Java stack trace (for programmers):
----

Does anyone has an Idea what I am doing wrong here? Thank you in advance.

balex
  • 273
  • 1
  • 7
  • 18
  • Possible duplicate of [freemarker not assign staticUtil in liferay 7](https://stackoverflow.com/questions/37341835/freemarker-not-assign-staticutil-in-liferay-7) – Manticore Jul 06 '17 at 13:50

1 Answers1

4

in liferay 7 they have change the setting of freemarker engine now the configurazion is in the control panel

Control Panel -> Configuration -> System Settings
-> Foundation -> FreeMarker Engine -> Restricted Variables

you have to remove here the restrict varibles

The package of object are changed in liferay 7 so the correcti freemarker in this case is

<#assign journalArticleId = .vars['reserved-article-id'].data>
<#assign journalArticleResourceLocalServiceUtil = staticUtil["com.liferay.journal.service.JournalArticleResourceLocalServiceUtil"]>
<#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil"]>

<#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId, journalArticleId)/>
<#assign categoryList=assetCategoryLocalServiceUtil.getCategories("com.liferay.journal.model.JournalArticle",articleResourcePK) >

<#list categoryList as categoryList>
${categoryList.getName()}
</#list>
Romeo Sheshi
  • 901
  • 5
  • 7
  • Thank you for your reply the staticUtil is theoretically working now, but now i have this error: `low-level message: java.lang.ClassNotFoundException: com.liferay.journal.service.JournalArticleResourceLocalServiceUtil cannot be found by com.liferay.portal.template.freemarker_2.0.7 ` , do you have any ideas what the problem is? – balex Jul 11 '16 at 09:01
  • you have remove only the staticUtil from restricted variables? – Romeo Sheshi Jul 11 '16 at 09:04
  • No, i have removed all restricted classes and variables. – balex Jul 11 '16 at 09:07
  • WOW it's working now, thank you so much for your soloution and your effort! – balex Jul 11 '16 at 09:22
  • you're welcome, its better to delete the other question you open before so it's not dupplicated – Romeo Sheshi Jul 11 '16 at 09:25
  • I heard of a bug that won't let portal start up, if you simply delete the restriction leaving an empty string behind. Is that still the case? https://web.liferay.com/de/community/forums/-/message_boards/message/73391506?_19_threadView=tree#_19_message_74729187 – Manticore Jul 06 '17 at 13:49