views:

66

answers:

3

I am trying to get the HttpServletResponse from liferay portal. I am also working with icefaces.

PortletResponse response1 = (PortletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
        HttpServletResponse response = (HttpServletResponse)response1;

I get the following Exception:

Caused by: java.lang.ClassCastException: com.liferay.portlet.RenderResponseImpl cannot be cast to javax.servlet.http.HttpServletResponse
+1  A: 

May be this Helps

Generate PDF File in Portlet

Feras
+1  A: 

FacesContext will return PortletRequest/Response objects if you are using the portlet bridge.

What are you trying to do with the HttpServletResponse?

If you are trying to generate binary content, this will only work in the Resource phase of a JSR 286 portlet (otherwise you cannot set headers). It will never work in a JSR 168 portlet. If you need to do this in a JSR 168 portlet, you need to use a helper servlet.

In any case, if you are trying to use a third party lib that requires HttpServletResponse for its API, you can use a PortletRequestDispatcher to dispatch to a JSP or a servlet and then use the HttpServletResponse that is available to you there.

bgould
+1  A: 

Try PortalUtil.getHttpServletResponse(portletResponse)

dtruong