论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Jigar N Gajjar
httpservletrequest in icefaces portlet
2010年5月11日 下午11:05
答复

Jigar N Gajjar

等级: Junior Member

帖子: 53

加入日期: 2009年12月24日

最近的帖子

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
2012年4月30日 上午3:56
答复

Jagat Pandya

等级: New Member

帖子: 5

加入日期: 2010年11月22日

最近的帖子

HttpServletRequest httpRequest = (HttpServletRequest) (FacesContext
.getCurrentInstance().getExternalContext().getRequestMap()
.get("com.liferay.portal.kernel.servlet.PortletServletRequest"));
David H Nebinger
RE: httpservletrequest in icefaces portlet
2012年4月30日 上午9:06
答复

David H Nebinger

等级: Liferay Legend

帖子: 7151

加入日期: 2006年9月1日

最近的帖子

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.