Fórumok

6.2 Freemarker serviceLocator variable

thumbnail
Ken Driscoll, módosítva 10 év-val korábban

6.2 Freemarker serviceLocator variable

Junior Member Bejegyzések: 57 Csatlakozás dátuma: 2012.07.02. Legújabb bejegyzések
I recently upgraded to Liferay 6.2 GA1, and now all of my custom Asset Publisher Display Templates (using Freemarker) throw errors saying "Expression serviceLocator is undefined". I did some research, and already have the following in my portal-ext.properties file:
journal.template.velocity.restricted.variables=
journal.template.freemarker.restricted.variables=

This had worked in the past to give me access to the "serviceLocator" variable, but now I no longer have it. Did something change in 6.2 that is causing this issue?

Thanks in advance.
thumbnail
James Falkner, módosítva 10 év-val korábban

RE: 6.2 Freemarker serviceLocator variable

Liferay Legend Bejegyzések: 1399 Csatlakozás dátuma: 2010.09.17. Legújabb bejegyzések
Ken Driscoll:
I recently upgraded to Liferay 6.2 GA1, and now all of my custom Asset Publisher Display Templates (using Freemarker) throw errors saying "Expression serviceLocator is undefined". I did some research, and already have the following in my portal-ext.properties file:
journal.template.velocity.restricted.variables=
journal.template.freemarker.restricted.variables=

This had worked in the past to give me access to the "serviceLocator" variable, but now I no longer have it. Did something change in 6.2 that is causing this issue?

Thanks in advance.


The names of the configuration settings have changed (again).

They are now more generic, since variables like serviceLocator can also be used from other contexts like DDL templates and ADTs.. so try
velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=


This will allow you to do everything you could do in 6.1. Also note that the new variables *.restricted.classes are there for a very good reason, and by default prevent unrestricted JVM class access, and should not disabled without fully understanding and accepting the consequences (that a web content template can take down your system, wipe out your production DB, or worse).
thumbnail
Ken Driscoll, módosítva 10 év-val korábban

RE: 6.2 Freemarker serviceLocator variable

Junior Member Bejegyzések: 57 Csatlakozás dátuma: 2012.07.02. Legújabb bejegyzések
Many thanks James!
thumbnail
Alberto Glez, módosítva 9 év-val korábban

RE: 6.2 Freemarker serviceLocator variable

New Member Bejegyzések: 3 Csatlakozás dátuma: 2014.01.07. Legújabb bejegyzések
This really save my day!! Many thanks James!
thumbnail
Enrique Valdes Lacasa, módosítva 9 év-val korábban

RE: 6.2 Freemarker serviceLocator variable

Junior Member Bejegyzések: 92 Csatlakozás dátuma: 2014.07.29. Legújabb bejegyzések
Hello everyone, and thank you James for the clarification. I have a question though, maybe someone in here can help.

I am implementing an Application Display Template (ADT) for the Asset Publisher. I am trying to retrieve the URL of a file in the document library to display it as a link for the users. The thing is that it looks like I will need to use some service in the ADT, so using the $serviceLocator variable could be very useful. But I am seeing in the Documentation of Portal Properties - Liferay 6.2 that it looks like this property is set by default: velocity.engine.restricted.variables=serviceLocator.

So this made me think...maybe this is because the use of the $serviceLocator variable is not quite recommended. Reading the description of the property, it says something like: "...this variable will be restricted in: DDL templates, Journal templates and Portlet Display Templates."...so:

1) Are ADTs included as DDL Templates, Journal templates or Portlet Display Templates?
2) Should I use service locator?
3) If the use of service locator is not recommended...would anyone have a better suggestion to implement this functionality?

Thanks and Happy Hollidays!
Andreas Wittig, módosítva 6 év-val korábban

RE: 6.2 Freemarker serviceLocator variable

New Member Bejegyzések: 3 Csatlakozás dátuma: 2017.06.01. Legújabb bejegyzések
At least I got some answer from lester.pi@liferay.com regarding https://issues.liferay.com/browse/LPS-58698 :
"If you decide to have "velocity.engine.restricted.variables" empty then any user with permission to update/create templates can become administrator"