如何在config(Liferay)中获取portlet上下文?

时间:2014-01-15 14:32:39

标签: liferay portlet

我想在config mod中访问portlet的Context(在我的ConfigurationAction接口的实现中)。

我在几个小时内尝试在ConfigurationActionImpl.processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)中获取与doView(RenderRequest renderRequest, RenderResponse renderResponse)中相同的上下文,但没有任何好结果。

在我的doView()中,我可以使用getPortletContext()(与getPortletConfig().getPortletContext()相同)和renderRequest.getPortletSession()(它的>来访问我的portlet上下文上下文实例),但我不知道如何从我的processAction()访问其中一个对象。

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

这是我最终使用的方法:

PortletBag portletBag = PortletBagPool.get(portletId);
DispatcherPortlet portlet = (DispatcherPortlet)portletBag.getPortletInstance();

PortletContext pCtx = portlet.getPortletContext();

如果您想要计算portletId,可以执行以下操作:

String portletResource = ParamUtil.getString(renderRequest, "portletResource");
String portletId;
if (portletResource.contains("_INSTANCE")) {
    portletId = portletResource.substring(0, portletResource.indexOf("_INSTANCE"));
} else {
    portletId = portletResource;
}

作为旁注,我想提一下,我需要它才能获得portlet的Spring ApplicationContext,我用这个做了:

PortletContext pCtx = portlet.getPortletContext();
ApplicationContext portletAppContext = (ApplicationContext)pCtx.getAttribute(FrameworkPortlet.PORTLET_CONTEXT_PREFIX + portlet.getPortletName());
相关问题