Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Jigar N Gajjar
httpservletrequest in icefaces portlet
11 de mayo de 2010 23:05
Respuesta

Jigar N Gajjar

Ranking: Junior Member

Mensajes: 71

Fecha de incorporación: 24 de diciembre de 2009

Mensajes recientes

Hi,
i want to get httpservletrequest from the icefaces portlet, i am using

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();

but it is giving classcastexcpetion as it is not able to cast in httpservletrequest


Thanks
Jigar Gajjar
Jagat Pandya
RE: httpservletrequest in icefaces portlet
30 de abril de 2012 3:56
Respuesta

Jagat Pandya

Ranking: New Member

Mensajes: 7

Fecha de incorporación: 22 de noviembre de 2010

Mensajes recientes

HttpServletRequest httpRequest = (HttpServletRequest) (FacesContext
.getCurrentInstance().getExternalContext().getRequestMap()
.get("com.liferay.portal.kernel.servlet.PortletServletRequest"));
David H Nebinger
RE: httpservletrequest in icefaces portlet
30 de abril de 2012 9:06
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 13216

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

Jagat Pandya:
HttpServletRequest httpRequest = (HttpServletRequest) (FacesContext
.getCurrentInstance().getExternalContext().getRequestMap()
.get("com.liferay.portal.kernel.servlet.PortletServletRequest"));



Wrong wrong wrong.

First, the OP's code fails because:

1FacesContext fc = FacesContext.getCurrentInstance();
2HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();


The request instance is a PortletRequest, not an HttpServletRequest. Cast it to a PortletRequest and you're fine.

Second, if you need the original HttpServletRequest (which I highly doubt because no one in the portlet world typically needs this request), you use the com.liferay.portal.util.PortalUtil.getHttpServletRequest(PortletRequest) to access it.

Do not attempt Jagat's 'back door' access because it may break in the future, where the API will be maintained.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!