Foros de discusión

6.2 Freemarker serviceLocator variable

thumbnail
Ken Driscoll, modificado hace 10 años.

6.2 Freemarker serviceLocator variable

Junior Member Mensajes: 57 Fecha de incorporación: 2/07/12 Mensajes recientes
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, modificado hace 10 años.

RE: 6.2 Freemarker serviceLocator variable

Liferay Legend Mensajes: 1399 Fecha de incorporación: 17/09/10 Mensajes recientes
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, modificado hace 10 años.

RE: 6.2 Freemarker serviceLocator variable

Junior Member Mensajes: 57 Fecha de incorporación: 2/07/12 Mensajes recientes
Many thanks James!
thumbnail
Alberto Glez, modificado hace 9 años.

RE: 6.2 Freemarker serviceLocator variable

New Member Mensajes: 3 Fecha de incorporación: 7/01/14 Mensajes recientes
This really save my day!! Many thanks James!
thumbnail
Enrique Valdes Lacasa, modificado hace 9 años.

RE: 6.2 Freemarker serviceLocator variable

Junior Member Mensajes: 92 Fecha de incorporación: 29/07/14 Mensajes recientes
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, modificado hace 6 años.

RE: 6.2 Freemarker serviceLocator variable

New Member Mensajes: 3 Fecha de incorporación: 1/06/17 Mensajes recientes
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"