Foros de discusión

Need Solution

Paramita Nandi, modificado hace 8 años.

Need Solution

New Member Mensajes: 23 Fecha de incorporación: 5/03/12 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

Liferay Master Mensajes: 735 Fecha de incorporación: 5/07/11 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

Liferay Master Mensajes: 735 Fecha de incorporación: 5/07/11 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

New Member Mensajes: 23 Fecha de incorporación: 5/03/12 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
You could do it the same way the portal does - open/parse the liferay-display.xml file and read the category.
thumbnail
Andew Jardine, modificado hace 8 años.

RE: Need Solution

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

New Member Mensajes: 23 Fecha de incorporación: 5/03/12 Mensajes recientes
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, modificado hace 8 años.

RE: Need Solution

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Can you share with us your code as well as the name of your project, portlet.xml and liferay-display.xml files?
Paramita Nandi, modificado hace 8 años.

RE: Need Solution

New Member Mensajes: 23 Fecha de incorporación: 5/03/12 Mensajes recientes
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();
}