フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Jigar N Gajjar
httpservletrequest in icefaces portlet
2010/05/11 23:05
答え

Jigar N Gajjar

ランク: Junior Member

投稿: 70

参加年月日: 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/04/30 3:56
答え

Jagat Pandya

ランク: New Member

投稿: 7

参加年月日: 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/04/30 9:06
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12529

参加年月日: 2006/09/01

最近の投稿

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.