8

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= 
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
lee trj
  • 83
  • 1
  • 5

5 Answers5

7

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.

Totò
  • 1,824
  • 15
  • 20
  • it does not seem to work in my local environment. I did exactly as you said. Do you know if this is already deprecated? – Manticore Jul 06 '17 at 13:43
  • This is the correct procedure for LR 7, but just as an increment here, you might fine tune to use what you need leaving other restrictions... restrictedVariables=["","utilLocator","objectUtil","staticFieldGetter","staticUtil"] – Victor Dec 01 '17 at 22:28
5

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)

  • 3
    They are not ignored, they have been moved into OSGI config files. Depending on the version and service pack I've experienced that updating them from the control panel may cause the Liferay instance to brake (not startup anymore) so I strongly discourage doing that – Totò Mar 31 '17 at 05:42
  • 1
    I've also had Liferay DXP break when updating those values from the control panel. You have to do some database Foo to get LR to boot again. I'll upvote you above. – David George Apr 03 '17 at 07:41
  • 1
    For anyone who has problems with LR booting this is what I did to get LR starting again: https://youtu.be/Aot3oRP7hDg – David George Apr 03 '17 at 07:42
  • @Totò I have tried creating a file com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg in osgi folder as metioned in the answer below, but it does not seem to have an effect. Do you know what's wrong with it? – Manticore Jul 06 '17 at 13:16
3
  • 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.

2

In liferay 7.1. you will find Freemaker Engine under

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

zx485
  • 28,498
  • 28
  • 50
  • 59
1

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

com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.config