Freemarker does not assign staticUtil
Asked Answered
R

5

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= 
Rhpositive answered 20/5, 2016 at 8:34 Comment(0)
R
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.

Revisionism answered 31/3, 2017 at 5:41 Comment(2)
it does not seem to work in my local environment. I did exactly as you said. Do you know if this is already deprecated?Foreknow
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"]Heterodoxy
U
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)

Unbeliever answered 24/10, 2016 at 11:34 Comment(4)
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 thatDaudet
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.Dagenham
For anyone who has problems with LR booting this is what I did to get LR starting again: youtu.be/Aot3oRP7hDgDagenham
@Revisionism 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?Foreknow
R
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.

Ramos answered 30/3, 2018 at 12:6 Comment(0)
M
2

In liferay 7.1. you will find Freemaker Engine under

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

Myrtice answered 5/10, 2018 at 9:19 Comment(0)
P
1

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

com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.config
Perspicacity answered 17/5, 2019 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.