Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to access DLURLHelper in a Fragment
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
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.