Freemarker does not assign staticUtil

2020-06-17 05:07发布

I worked Application Display Templates on liferay 6.2, I use freemarker help pagination the dynamics data list of liferay. When I upgrade to liferay 7, it is a problem. Liferay 7 use code <#assign records = ddlDisplayTemplateHelper.getRecords(reserved_record_set_id)> for get a records.

Old code:

<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")> <#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)> <#assign totalRecord = DDLRecordLocalService.getRecordsCount(reserved_record_set_id, 0) >

It doesn't work.

So I try <#assign serviceLocator = staticUtil["com.liferay.portal.template.ServiceLocator"]> but staticUtil get an error.

The following has evaluated to null or missing: ==> staticUtil [in template "20115#20159#21387" at line 9, column 27] Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing

In portal-ext.properties I have added:

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

5条回答
孤傲高冷的网名
2楼-- · 2020-06-17 05:31

In liferay 7.1. you will find Freemaker Engine under

Control Panel -> System Settings -> Platform -> Template Engines

查看更多
干净又极端
3楼-- · 2020-06-17 05:39

I think those properties in portal-ext.properties are just ignored in liferay 7.

You can admin those properties in Control Panel → Configuration → System Settings → Foundation → FreeMarker Engine and remove "staticUtil" (or remove "serviceLocator" directly) from restricted variables. (liferay reboot is required)

查看更多
\"骚年 ilove
4楼-- · 2020-06-17 05:41

The properties you refer to have been moved to an OSGI config in Liferay 7/DXP. To deploy them you need to create a file named com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg and place it under $LIFERAY_HOME/osgi/configs

The content of the file will be the following:

restrictedVariables=

To find all the configs and their defaults you can have a look at the class com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration

That you can find in the Liferay source code.

查看更多
Emotional °昔
5楼-- · 2020-06-17 05:44

In liferay-ce-portal-7.1.1.2-ga3 version, the file is renamed to

com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.config
查看更多
再贱就再见
6楼-- · 2020-06-17 05:45
  • Go to Control Panel -> System Settings -> Foundation Page

  • Find FreeMarker Engine from list click on it .

  • Remove serviceLocator variable and staticUtil from restricted variables by Clicking on (-) icon.

  • If you want to use staticUtil object then also remove this variable from restricted variables.

  • Save it.

  • Restart Liferay server.

You will direct access to serviceLocator object in your Application Display Template.

查看更多
登录 后发表回答