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
Deryk Sinotte
created issue -
Deryk Sinotte
made changes -
Field | Original Value | New Value |
---|---|---|
Assignee | Ken Fyten [ ken.fyten ] |
Ken Fyten
made changes -
Assignee | Ken Fyten [ ken.fyten ] | Arturo Zambrano [ artzambrano ] |
Assignee Priority | P2 [ 10011 ] |
Ken Fyten
made changes -
Assignee Priority | P2 [ 10011 ] | P1 [ 10010 ] |
Arturo Zambrano
made changes -
Status | Open [ 1 ] | Resolved [ 5 ] |
Resolution | Fixed [ 1 ] |
Ken Fyten
made changes -
Fix Version/s | 4.0 [ 11382 ] |
Ken Fyten
made changes -
Status | Resolved [ 5 ] | Closed [ 6 ] |