Foren

Get portlet context without request

Matthew K., geändert vor 8 Jahren.

Get portlet context without request

Junior Member Beiträge: 74 Beitrittsdatum: 31.08.15 Neueste Beiträge
Hello!
I think the title says everything. So I am in a workflow handler where I have no access to a themeDisplay or request object. I want to call a function of another portlet which needs a request object to obtain the portlet context. Is there a possibility to get the portlet context without both of these variables?
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: Get portlet context without request

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Um, no. A workflow can get invoked from a non-portlet activity.

for example, using Liferay Sync to upload a file may invoke a workflow if they are defined for docs and media.
Matthew K., geändert vor 8 Jahren.

RE: Get portlet context without request

Junior Member Beiträge: 74 Beitrittsdatum: 31.08.15 Neueste Beiträge
OK. Then I will do it differently by using the portlet id.

PortletBag portletBag = PortletBagPool.get("PortletName_WAR_PortletNameportlet");
GenericPortlet portletInstance = (GenericPortlet)portletBag.getPortletInstance();
PortletContext portletContext = portletInstance.getPortletContext();
thumbnail
Olaf Kock, geändert vor 8 Jahren.

RE: Get portlet context without request

Liferay Legend Beiträge: 6403 Beitrittsdatum: 23.09.08 Neueste Beiträge
Not sure if that's a good way to go. What is the method that you need to call? Typically portlets are the UI layer of an application and you shouldn't call into that layer from anywhere (why make your workflow dependent on the UI anyway?)

If you've written that code yourself, you should rather move it out of the portlet layer into the business layer. If it's Liferay code, it might be more maintainable to look at the API that the method in question calls and call that API yourself. Even if you have to copy a few lines of code in order to prepare/convert the parameters.
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: Get portlet context without request

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
You don't want to bind to a portlet because, after all, the portlet might not be available.

Usually when you have a non-UI component that needs to notify a UI component, you'd use something like the LMB or even a data store (depending upon whether the target needed notification or if polling was okay).

Anything you can do to decouple the arrangement is a good thing...
Matthew K., geändert vor 8 Jahren.

RE: Get portlet context without request

Junior Member Beiträge: 74 Beitrittsdatum: 31.08.15 Neueste Beiträge
OK, the problem is that I need to parse a css file from a specific portlet by another portlet. So I need something like a global css-file.
Maybe it's a good idea to put this css-file into a theme. I just tested it but I cannot get the css-file as an input stream. I only get it as an URL. So I need something like getResourceAsStream(THEME_PATH + "/css/css_file.css"). But how do I get that theme path?

EDIT: OK. I am using this now:

cssUrl = new URL(PortalUtil.getPortalURL(company.getVirtualHostname(), PortalUtil.getPortalPort(false), false) +
					theme.getContextPath() + theme.getCssPath() + "/" + cssFile);
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: Get portlet context without request

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
You can't. getResourceAsStream() is limited to what your class loader can read, it's not a system-wide reader.

Of course your CSS should be at the theme level. Since you need it in multiple portlets you should either move it to the theme or merge the two portlets into a single project.