Liferay:从init()获取PortletID和companyID [英] Liferay: get PortletID and companyID from init()

查看:74
本文介绍了Liferay:从init()获取PortletID和companyID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许通过init(PortletConfig)中的PortletConfig

Maybe trough PortletConfig in init(PortletConfig)

问题是使用

((PortletConfigImpl) portletConfig).getPortletId();

不再允许,因为在package.properties中添加portal-impl.jar会导致在尝试执行构建ant目标时抛出异常,并说这不再允许了.

is not allowed anymore because adding portal-impl.jar in package.properties gives throws an exception when trying to execute build ant target, saying that this is not allowed anymore

对于companyID,我直接不知道从哪里开始.我目前正在使用

For companyID I directly have no idea where to start. I am using currently

long companyId = CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId();

但是一旦我拥有多家公司,它就会失败

but as soon as I got more than one company it will fail

如果我只能以某种方式获取Portlet对象,我认为同时获取portletId和companyId就足够了

If only I could get Portlet object somehow, I think it would be enough to get both portletId and companyId

推荐答案

您可以通过从portletId来从PortletConfig获得Portlet. com/portlet-api/2.0/javadocs/javax/portlet/PortletConfig.html#getPortletName%28%29"rel =" nofollow noreferrer"title =" Portlet API 2.0文档> Portletconfig.getPortletName() ,然后使用

You can get the Portlet from PortletConfig through the portletId got from the method Portletconfig.getPortletName() and then using PortletLocalServiceUtil.getPortletById(String):

// I have not tried this but I think it should work
String portletName = Portletconfig.getPortletName();
Portlet portlet = PortletLocalServiceUtil.getPortletById(portletName);
long companyId = portlet.getCompanyId();

然后从Portlet中可以轻松获得companyId.

And then from the Portlet you can easily get the companyId.

警告语 ,如奥拉夫·科克(Olaf Kock)在其答案,因此这里是另一个

A word of caution as stated by Olaf Kock in his answer, hence here is another answer which gives you some alternative to fetch the companyId if you know some aspect of the company. This approach does not fetch the companyId from the portlet instance for the reasons as explained by Olaf Kock.

尝试这种方法,看看是否有帮助.

Try this approach and see if this helps.

这篇关于Liferay:从init()获取PortletID和companyID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆