留言板

Need Solution

Paramita Nandi,修改在8 年前。

Need Solution

New Member 帖子: 23 加入日期: 12-3-5 最近的帖子
I am trying to import com.liferay.portal.util.WebAppPool in my custom portlet but the import can not be resolved.
I am not able to find the solution. Anyone have any idea?
thumbnail
Jan Geißler,修改在8 年前。

RE: Need Solution

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
There is no solution, as you try to import a class which is not exposed vie any service jar. WebAppPool resides in portal-impl.jar which is the jar for all internal implementations. You don't have access to them in a portlet.
thumbnail
David H Nebinger,修改在8 年前。

RE: Need Solution

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Paramita Nandi:
I am trying to import com.liferay.portal.util.WebAppPool in my custom portlet but the import can not be resolved.
I am not able to find the solution. Anyone have any idea?


Why?

WebAppPool really only holds the PortletCategory instances for the companies in the portal. In fact I've never heard of this class as for all the years I've been doing Liferay I've never needed it. There's likely really no reason for you to be accessing that class at all.

The fact that you need it to me indicates that you're doing something that you really shouldn't be.
thumbnail
Jan Geißler,修改在8 年前。

RE: Need Solution

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
David H Nebinger:
In fact I've never heard of this class as for all the years I've been doing Liferay I've never needed it


Me too emoticon
Paramita Nandi,修改在8 年前。

RE: Need Solution

New Member 帖子: 23 加入日期: 12-3-5 最近的帖子
David H Nebinger:
Paramita Nandi:
I am trying to import com.liferay.portal.util.WebAppPool in my custom portlet but the import can not be resolved.
I am not able to find the solution. Anyone have any idea?


Why?

WebAppPool really only holds the PortletCategory instances for the companies in the portal. In fact I've never heard of this class as for all the years I've been doing Liferay I've never needed it. There's likely really no reason for you to be accessing that class at all.

The fact that you need it to me indicates that you're doing something that you really shouldn't be.



I am using com.liferay.portal.util.WebAppPool to get the category details in which a portlet is added.
<display>
<category name="category.sampleJms">
<portlet id="SampleJMS-Portlet" />
</category>
</display>


I want to get "category.sampleJms" for SampleJMS-Portlet.

Could you please suggest me any other way to do the same?
thumbnail
David H Nebinger,修改在8 年前。

RE: Need Solution

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
You could do it the same way the portal does - open/parse the liferay-display.xml file and read the category.
thumbnail
Andew Jardine,修改在8 年前。

RE: Need Solution

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hey Paramita,

Try this out and see if it works for you. It's untested on my side, but I just plucked a few lines here and there from the Portal's source. Should do the trick for you.


String portletId = "my-portlet-id";
PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();
String xml = HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-display.xml"));
PortletCategory newPortletCategory =	PortletLocalServiceUtil.getWARDisplay(servletContextName, xml);
Paramita Nandi,修改在8 年前。

RE: Need Solution

New Member 帖子: 23 加入日期: 12-3-5 最近的帖子
Andew Jardine:
Hey Paramita,

Try this out and see if it works for you. It's untested on my side, but I just plucked a few lines here and there from the Portal's source. Should do the trick for you.


String portletId = "my-portlet-id";
PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();
String xml = HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-display.xml"));
PortletCategory newPortletCategory =	PortletLocalServiceUtil.getWARDisplay(servletContextName, xml);


Hi Andew,

It is not working. Category name is coming as "root" for all portlets.
I am fetching the category name using newPortletCategory .getName()
thumbnail
Andew Jardine,修改在8 年前。

RE: Need Solution

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Can you share with us your code as well as the name of your project, portlet.xml and liferay-display.xml files?
Paramita Nandi,修改在8 年前。

RE: Need Solution

New Member 帖子: 23 加入日期: 12-3-5 最近的帖子
Andew Jardine:
Can you share with us your code as well as the name of your project, portlet.xml and liferay-display.xml files?


Hi

I am executing the code as groovy script from Liferay 6.2 control panel for testing. I have used portlet id of Sign in Portlet.
Hereunder is my code

import javax.servlet.ServletContext;
import com.liferay.portal.kernel.portlet.PortletBag;
import com.liferay.portal.kernel.portlet.PortletBagPool;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.model.Portlet;
import com.liferay.portal.model.PortletCategory;
import com.liferay.portal.service.PortletLocalServiceUtil;


PortletBag portletBag = PortletBagPool.get("58");
ServletContext servletContext = portletBag.getServletContext();
def xml;
try {
xml = HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-display.xml"));
PortletCategory newPortletCategory = PortletLocalServiceUtil.getWARDisplay(servletContext.getServletContextName(), xml);

out.println("Category name ="+newPortletCategory.getName());

} catch (MalformedURLException e) {

e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}