问题描述
也许通过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()
,然后使用 PortletLocalServiceUtil.getPortletById(String)
:
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)在其答案,因此这里是另一个答案,如果您了解公司的某些方面,则可以通过其他方法来获取companyId
.由于Olaf Kock解释的原因,该方法无法从portlet实例中获取companyId
.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!