ClassCastException when using Flash scope and Ajax
hamzabenmansour May 24, 2013 8:33 AMHi,
I have a JSF 2.0 portlet running on eXo Platform 3.5 and JBoss EAP 5 using portletBridge 3.1.2.Final. I defined an error page for my portlet which may display the exception message. When an error occur, a custom ExceptionHandler extracts the message, puts it in the flash scope and redirects to the error page after calling the NavigationHandler (with a redirect).
I have one complex page comprised of different forms submitted with a4j:commandLink components. when I submit one form and an unexpected Exception occurs, the error page is not diplayed and I have in the logs
javax.faces.FacesException: javax.faces.FacesException: .....
.....
Caused by: java.lang.ClassCastException: org.jboss.portletbridge.context.flash.FlashHttpServletAdapter cannot be cast to javax.portlet.PortletResponse
at org.jboss.portletbridge.context.PortletExternalContextImpl.getPortletResponse(PortletExternalContextImpl.java:186)
at org.jboss.portletbridge.context.PortletExternalContextImpl.getNamespace(PortletExternalContextImpl.java:195)
at org.jboss.portletbridge.context.AbstractExternalContext.encodeNamespace(AbstractExternalContext.java:152)
at javax.faces.context.ExternalContextWrapper.encodeNamespace(ExternalContextWrapper.java:115)
at javax.portlet.faces.component.PortletNamingContainerUIViewRoot.setId(PortletNamingContainerUIViewRoot.java:59)
at javax.faces.component.UIViewRoot.<init>(UIViewRoot.java:211)
at javax.portlet.faces.component.PortletNamingContainerUIViewRoot.<init>(PortletNamingContainerUIViewRoot.java:47)
at sun.reflect.GeneratedConstructorAccessor529.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at com.sun.faces.application.ApplicationImpl.newThing(ApplicationImpl.java:1727)
When, debugging, the implementation of the externalContext used is the ResourceRequestExternalContextImpl (due to the AJAX request) where we cast the response, which is in our case a FlashHttpServletAdapter to a PortletResponse.
The work around in my case was to simply remove the use of the flash scope.
Is this scope supported ? Or am I misusing the API ?
Thanks a lot for your help