问题
I'd like to access the Context of the portlet in config mod (in my implement of ConfigurationAction interface).
I try since hours to get the same Context in my ConfigurationActionImpl.processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) as I have in my doView(RenderRequest renderRequest, RenderResponse renderResponse), but without any good result.
In my doView(), I can access my portlet Context using getPortletContext() (same as getPortletConfig().getPortletContext()) and renderRequest.getPortletSession() (it's NOT the same Context instances), but I don't know how I can access one of those objects from my processAction().
Can somebody help me, please ?
回答1:
This is the method I ended up using:
PortletBag portletBag = PortletBagPool.get(portletId);
DispatcherPortlet portlet = (DispatcherPortlet)portletBag.getPortletInstance();
PortletContext pCtx = portlet.getPortletContext();
In case you want to compute the portletId, you can do this:
String portletResource = ParamUtil.getString(renderRequest, "portletResource");
String portletId;
if (portletResource.contains("_INSTANCE")) {
portletId = portletResource.substring(0, portletResource.indexOf("_INSTANCE"));
} else {
portletId = portletResource;
}
As a side note, I want to mention that I needed it in order to be able to get the Spring ApplicationContext of the portlet, which I did with this:
PortletContext pCtx = portlet.getPortletContext();
ApplicationContext portletAppContext = (ApplicationContext)pCtx.getAttribute(FrameworkPortlet.PORTLET_CONTEXT_PREFIX + portlet.getPortletName());
来源:https://stackoverflow.com/questions/21140154/how-to-get-portlet-context-in-config-liferay