本文介绍了如何在config(Liferay)中获取portlet上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想在config mod中访问Portlet的上下文(在我的ConfigurationAction接口的实现中).

I'd like to access the Context of the portlet in config mod (in my implement of ConfigurationAction interface).

几个小时以来,我一直试图在我的ConfigurationActionImpl.processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)中获得与我在doView(RenderRequest renderRequest, RenderResponse renderResponse)中相同的上下文,但是没有任何好结果.

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.

在我的doView()中,我可以使用getPortletContext()(与getPortletConfig().getPortletContext()相同)和renderRequest.getPortletSession()(它不是相同的Context实例,是 NOT )来访问我的Portlet Context,但是我不能不知道如何从processAction()访问这些对象之一.

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().

请问有人可以帮我吗?

推荐答案

这是我最终使用的方法:

This is the method I ended up using:

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

PortletContext pCtx = portlet.getPortletContext();

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

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;
}

作为旁注,我想提到我需要它,以便能够获得portlet的Spring ApplicationContext,对此我做了以下工作:

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());

这篇关于如何在config(Liferay)中获取portlet上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:45