Foren

Getting ServletContext from PortletContext (without struts)

thumbnail
Emmanuel Guiton, geändert vor 12 Jahren.

Getting ServletContext from PortletContext (without struts)

Junior Member Beiträge: 39 Beitrittsdatum: 03.12.10 Neueste Beiträge
Hello All,

I need to access the ServletContext of a custom portlet from the init() method of the main class (the one that extends the LiferayPortlet() class).

I found hints on how to do it with LiferayServletContextProviderWrapper but as far as I understand it, this requires that the portlet is a STRUTS portlet (which mine is not).
For instance, using this class I only get a NoClassDefFoundError on org.apache.portals.bridges.common.ServletContextProvider since it is only defined in a jar (portals-bridges.jar) which is part of the ROOT webapp (thus, outside of the context of my portlet).

I am also very frustrated since the Liferay implementation of the PortletContext interface includes the ServletContext and a getServletContext() method, but I cannot access it since the classes in the portal-impl package are also out of the scope of my portlet.

Is there anyway to get the ServletContext from the LiferayPortlet class ?

Thanks for any tip,
- emmanuel
thumbnail
Emmanuel Guiton, geändert vor 12 Jahren.

RE: Getting ServletContext from PortletContext (without struts)

Junior Member Beiträge: 39 Beitrittsdatum: 03.12.10 Neueste Beiträge
Hi,

I found the solution I needed. In fact, it was almost nothing : Portletcontext and ServletContext share attributes. I was abled to set an attribute using the PortletContext in my Liferay portlet, and to fetch it in my servlet using the ServletContext. No need to fetch the PortletContext from the ServletContext or vice versa.

- emmanuel
thumbnail
Raja Nagendra Kumar, geändert vor 12 Jahren.

RE: Getting ServletContext from PortletContext (without struts)

Expert Beiträge: 484 Beitrittsdatum: 02.03.06 Neueste Beiträge
Your finding may not be true always.. specially in different war file servlets and portlets and container you are using...

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com