留言板
Need Solution
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?
I am not able to find the solution. Anyone have any idea?
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.
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.
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
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?
You could do it the same way the portal does - open/parse the liferay-display.xml file and read the category.
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.
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);
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()
Can you share with us your code as well as the name of your project, portlet.xml and liferay-display.xml files?
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();
}