0

我在 Liferay 7.1 中设置了一个名为 CustomLogo 的页面自定义字段。我想在免费标记模板中访问它的值。在阅读了文档和一些与之相关的帖子后,我使用以下代码访问自定义字段

<#assign page_custom_field_logo_url = layout.getGroup().getExpandoBridge().getAttribute("CustomLogo") />
<h1>${page_custom_field_logo_url }</h1> 

我已经为自定义字段设置了查看权限(所有用户角色)。我还检查了列名和值是否在 liferay 数据库(扩展表)中正确设置。但是我收到以下错误:

FreeMarker template error: Java method "com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.getAttribute(String)" threw an exception when invoked on com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl object "com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl@f2864c8"; see cause exception in the Java stack trace. FTL stack trace ("~" means nesting-related):
- Failed at: #assign page_custom_field_logo_url...  [in template "/templates/portal_normal.ftl" at line 75, column 37]

在观察堆栈跟踪时,我看到有一个空指针异常,它指出:

Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.getAttribute(ExpandoBridgeImpl.java:219)
at com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.getAttribute(ExpandoBridgeImpl.java:199)
Caused by: java.lang.NullPointerException
at com.liferay.portlet.expando.service.permission.ExpandoColumnPermissionImpl.contains(ExpandoColumnPermissionImpl.java:73)
at com.liferay.expando.kernel.service.permission.ExpandoColumnPermissionUtil.contains(ExpandoColumnPermissionUtil.java:58)
at com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(ExpandoValueServiceImpl.java:121)
at sun.reflect.GeneratedMethodAccessor1066.invoke(Unknown Source)

如上所述,我已经为自定义字段设置了查看权限。我还仔细检查了密钥、拼写错误和可能的错误,但没有成功。

如果您有任何建议或我错过的事情,请告诉我。谢谢

4

1 回答 1

1

尝试从布局而不是组中获取expando桥,所以

layout.getExpandoBridge().getAttribute("CustomLogo")

应该管用。

于 2019-06-19T09:46:53.973 回答