本文介绍了Liferay:从init(PortletConfig)获取PortletId和Plid [即,没有请求对象,只有PortletConfig]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想同时获得这两个值,并且由于在加载portlet时执行了init(Portletconfig),因此我对此值是否可用毫无疑问.

I would like to get both values, and since init(Portletconfig) is executed when loading the portlet, I don't see any doubt about whether this values should be available.

对于portletId,我尝试了

For portletId I tried

String portletId = ((PortletConfigImpl) portletConfig).getPortletId();

但是我似乎做不到.猜猜是因为impl在另一个jar中,不能从portlet中访问

but it seems I can't. Guess it is because the impl is in another jar not meant to be accessed from portlets

顺便说一句,我的主要目标是将两个参数都传递给另一个非请求上下文,这样我就可以做到

By the way, my main goal is to get to pass both params to another non-request context so I can do

final PortletPreferences prefs = PortletPreferencesFactoryUtil.getLayoutPortletSetup(LayoutLocalServiceUtil.getLayout(plid), portletId);

实时读取portlet的首选项.如果还有其他方法可以通过init()进行指示,例如获取整个首选项,就足够了

to read portlet's prefs in real time. If there is any other way to indicate that from init(), like getting the whole preferences it would be enough

编辑:我找到了另一种方法,并提出了一个稍有变化的新问题 Liferay:从init()获取PortletID和companyID

I found a different approach, and opened a new question with slightly changes Liferay: get PortletID and companyID from init()

推荐答案

所以...如果我理解正确,那么您的目标是在Portlet类的init方法中读取Portlet首选项.

So... If I understand it right, your goal is to read out portlet preferences inside the init method of your Portlet class.

根据API,可以从PortletRequest实例中检索PortletPreferences对象,该实例在doView()processAction()类中都可用.例如:

According to the API, the PortletPreferences object can be retrieved from a PortletRequest instance, which is available in both doView() and processAction() classes. E.g.:

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    String name = request.getPreferences().getValue("name", null);

    Writer writer = response.getWriter();
    writer.write("Hello, "+name+"!");
}

请务必注意,在Liferay中,默认情况下,portlet首选项仅存在于页面范围内,或者用Liferay术语,由plid标识的Layout是页面的简写形式布局ID.

It is important to note that in Liferay, portlet preferences by default only exist within the scope of a page, or, in Liferay terms, a Layout, which is identified by a plid, short-hand for page layout id.

关于您的init()方法,portlet API指示应在处理第一个portlet请求之前"调用该方法.在Liferay中,将在部署时间而不是在页面上添加portlet时创建portlet类的新实例(并且只有一个实例).实例化之后,门户网站容器将调用portlet类的init()方法.

Concerning your init() method, the portlet API dictates that this method should be called "before the first portlet request is handled". In Liferay, a new instance (and only ONE instance) of your portlet class is created at deploy time, not when you add a portlet on a page. After instantiation, the portal container will call the init() method of the portlet class.

结论:在portlet类的init()方法中检索portlet首选项根本没有任何意义,因为那时portlet没有任何上下文(读取为Layout)应该检索首选项.

Conclusion: it doesn't make sense at all to retrieve portlet preferences in the init() method of your portlet class, because at that point the portlet doesn't have any context (read: Layout) from which it should retrieve the preferences.

这篇关于Liferay:从init(PortletConfig)获取PortletId和Plid [即,没有请求对象,只有PortletConfig]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:44