留言板

httpservletrequest in icefaces portlet

Jigar N Gajjar,修改在13 年前。

httpservletrequest in icefaces portlet

Junior Member 帖子: 71 加入日期: 09-12-25 最近的帖子
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
thumbnail
Jagat Pandya,修改在11 年前。

RE: httpservletrequest in icefaces portlet

New Member 帖子: 7 加入日期: 10-11-22 最近的帖子
HttpServletRequest httpRequest = (HttpServletRequest) (FacesContext
.getCurrentInstance().getExternalContext().getRequestMap()
.get("com.liferay.portal.kernel.servlet.PortletServletRequest"));
thumbnail
David H Nebinger,修改在11 年前。

RE: httpservletrequest in icefaces portlet

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
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:

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest 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.
thumbnail
Neil Griffin,修改在11 年前。

moved thread to Liferay Faces forum

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
moved thread to Liferay Faces forum