Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 4.0.BETA
-
Component/s: ACE-Components
-
Labels:None
-
Environment:Portal
-
Assignee Priority:P1
Description
Neil from Liferay is currently seeing the following issue on the ICEfaces 4 trunk:
java.lang.ClassCastException: com.liferay.portlet.RenderRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest
at org.icefaces.ace.util.Utils.getRequest(Utils.java:527)
at org.icefaces.ace.util.Utils.getClientDescriptor(Utils.java:531)
at org.icefaces.ace.component.textentry.TextEntryRenderer.encodeEnd(TextEntryRenderer.java:97)
In reviewing the code I see that we are directly casting the request to HttpServletRequest:
public static HttpServletRequest getRequest(FacesContext facesContext){
return (HttpServletRequest)facesContext.getExternalContext().getRequest();
}
This will definitely cause problems in portlets. The two options:
1) Use JSF APIs if possible. For example when needing to use session attributes, use ExternalContext.getSessionMap() rather than HttpServletRequest.getSession.getAttribute(). This will ensure that it uses the PortletSession when running in that environment.
2) Use EnvUtil.getSafeRequest(FacesContext) which returns the PortletRequest wrapped to look like an HttpServletRequest. The warning here is that the full HttpServletRequest API is not implemented. In this case you might just need to change depending what parts of the request are being used.
public static HttpServletRequest getRequest(FacesContext facesContext){
return EnvUtils.getSafeRequest(facesContext);
// return (HttpServletRequest)facesContext.getExternalContext().getRequest();
}
java.lang.ClassCastException: com.liferay.portlet.RenderRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest
at org.icefaces.ace.util.Utils.getRequest(Utils.java:527)
at org.icefaces.ace.util.Utils.getClientDescriptor(Utils.java:531)
at org.icefaces.ace.component.textentry.TextEntryRenderer.encodeEnd(TextEntryRenderer.java:97)
In reviewing the code I see that we are directly casting the request to HttpServletRequest:
public static HttpServletRequest getRequest(FacesContext facesContext){
return (HttpServletRequest)facesContext.getExternalContext().getRequest();
}
This will definitely cause problems in portlets. The two options:
1) Use JSF APIs if possible. For example when needing to use session attributes, use ExternalContext.getSessionMap() rather than HttpServletRequest.getSession.getAttribute(). This will ensure that it uses the PortletSession when running in that environment.
2) Use EnvUtil.getSafeRequest(FacesContext) which returns the PortletRequest wrapped to look like an HttpServletRequest. The warning here is that the full HttpServletRequest API is not implemented. In this case you might just need to change depending what parts of the request are being used.
public static HttpServletRequest getRequest(FacesContext facesContext){
return EnvUtils.getSafeRequest(facesContext);
// return (HttpServletRequest)facesContext.getExternalContext().getRequest();
}
Activity
- All
- Comments
- History
- Activity
- Remote Attachments
- Subversion