How to get portlet context in config (Liferay)?

风格不统一 提交于 2019-12-13 05:14:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!