RE: How to access DLURLHelper in a Fragment

Olaf Kock, modified 2 Years ago. New Member Posts: 3 Join Date: 9/16/20 Recent Posts

Hello everyone,

I am working on a custom fragment that is using the itemSelector in the configuration.

My goal is once the user selects their item from the documents and media folder, I and retrieve the file URL.

However when I try: 

${serviceLocator.findService("com.liferay.document.library.util.DLURLHelper")}

I get the following error:

The following has evaluated to null or missing:
==> serviceLocator.findService("com.liferay.document.library.util.DLURLHelper") 

Based on the documentation it should work: https://docs.liferay.com/dxp/portal/7.4-latest/javadocs/portal-kernel/com/liferay/document/library/kernel/util/DLUtil.html

thumbnail
Olaf Kock, modified 2 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

serviceLocator is not available by default - for a good reason: Security.

Anybody with access to serviceLocator can effectively bypass all authentication checks by calling unauthenticated services. There is a way to enable it, but it's a galactically bad idea unless you're the only editor on your system and want to go the comfortable insecure route.

You might want to look into TemplateContextContributors that can make certain elements available to your freemarker scripts - but be very careful about the ones that you choose.