Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker does not assign staticUtil

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= 
like image 962
lee trj Avatar asked May 20 '16 08:05

lee trj


3 Answers

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.

like image 113
Totò Avatar answered Nov 02 '22 17:11

Totò


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)

like image 5
Miguel Ángel Júlvez Avatar answered Nov 02 '22 16:11

Miguel Ángel Júlvez


  • 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.

like image 3
Srushti Patel Avatar answered Nov 02 '22 16:11

Srushti Patel