Liferay 7 自由标记模板。 staticUtil 评估为 NULL 或缺失 - 试图获取 JournalArticle 的类别
Liferay 7 Freemarker Template. staticUtil has evaluated to NULL or missing - Tried to get JournalArticle's Categories
嗨,Liferay 的同胞们,
我正在尝试使用 Freemarker 模板获取 journalArticle 的类别。
我试过这段代码:
<#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>
我还将此行添加到 portal-setup-wizzard.properties
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
freemarker.engine.restricted.packages=
当我执行代码时它抛出这个错误:
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):
----
有没有人知道我在这里做错了什么?提前谢谢你。
在 liferay 7 中,他们更改了 freemarker 引擎的设置,现在配置在控制面板中
Control Panel -> Configuration -> System Settings
-> Foundation -> FreeMarker Engine -> Restricted Variables
你必须在这里删除限制变量
对象的包在 liferay 7 中发生了变化,所以在这种情况下更正的自由标记是
<#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>
嗨,Liferay 的同胞们,
我正在尝试使用 Freemarker 模板获取 journalArticle 的类别。
我试过这段代码:
<#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>
我还将此行添加到 portal-setup-wizzard.properties
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
freemarker.engine.restricted.packages=
当我执行代码时它抛出这个错误:
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):
----
有没有人知道我在这里做错了什么?提前谢谢你。
在 liferay 7 中,他们更改了 freemarker 引擎的设置,现在配置在控制面板中
Control Panel -> Configuration -> System Settings
-> Foundation -> FreeMarker Engine -> Restricted Variables
你必须在这里删除限制变量
对象的包在 liferay 7 中发生了变化,所以在这种情况下更正的自由标记是
<#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>