13 Replies Latest reply on Sep 26, 2011 8:23 PM by hantsy bai

    Exception when use customsized Converter and Ajax in Seam 3 application.

    hantsy bai Master

      I used a dropdown box to select country, then render the city selector and area selecter...
      But when i selected country, and tried to select city, I got an exception.




      18:43:54,638 ERROR [stderr] (http--127.0.0.1-8080-2) javax.faces.FacesException: Unexpected error restoring state for component with id editForm:addressCountry:input.  Cause: java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;.
      
      18:43:54,638 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:273)
      
      18:43:54,639 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
      
      18:43:54,639 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1485)
      
      18:43:54,639 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,641 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,642 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,642 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIForm.visitTree(UIForm.java:335)
      
      18:43:54,642 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,643 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,644 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
      
      18:43:54,644 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.component.visit.VisitUtils.doFullNonIteratingVisit(VisitUtils.java:75)
      
      18:43:54,644 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:257)
      
      18:43:54,644 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:181)
      
      18:43:54,644 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
      
      18:43:54,645 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:448)
      
      18:43:54,645 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
      
      18:43:54,645 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.ocpsoft.pretty.faces.application.PrettyViewHandler.restoreView(PrettyViewHandler.java:109)
      
      18:43:54,645 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:288)
      
      18:43:54,645 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:288)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:288)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:187)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      
      18:43:54,646 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
      
      18:43:54,647 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
      
      18:43:54,647 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      18:43:54,647 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)
      
      18:43:54,647 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      
      18:43:54,647 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      18:43:54,648 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
      
      18:43:54,648 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      
      18:43:54,648 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      18:43:54,648 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.seam.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
      
      18:43:54,648 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      
      18:43:54,649 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      18:43:54,649 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.seam.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:72)
      
      18:43:54,649 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
      
      18:43:54,649 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      
      18:43:54,649 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      
      18:43:54,650 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      
      18:43:54,650 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)
      
      18:43:54,650 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)
      
      18:43:54,650 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49)
      
      18:43:54,650 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)
      
      18:43:54,651 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      
      18:43:54,651 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      
      18:43:54,651 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
      
      18:43:54,651 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      
      18:43:54,651 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)
      
      18:43:54,652 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)
      
      18:43:54,652 ERROR [stderr] (http--127.0.0.1-8080-2)      at java.lang.Thread.run(Thread.java:662)
      
      18:43:54,652 ERROR [stderr] (http--127.0.0.1-8080-2) Caused by: java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
      
      18:43:54,652 ERROR [stderr] (http--127.0.0.1-8080-2)      at org.ajax4jsf.component.behavior.AjaxBehavior.restoreState(AjaxBehavior.java:343)
      
      18:43:54,652 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponentBase.restoreBehaviors(UIComponentBase.java:2056)
      
      18:43:54,653 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponentBase.restoreBehaviorsState(UIComponentBase.java:2023)
      
      18:43:54,653 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1443)
      
      18:43:54,653 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIOutput.restoreState(UIOutput.java:256)
      
      18:43:54,653 ERROR [stderr] (http--127.0.0.1-8080-2)      at javax.faces.component.UIInput.restoreState(UIInput.java:1379)
      
      18:43:54,653 ERROR [stderr] (http--127.0.0.1-8080-2)      at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:265)
      
      18:43:54,654 ERROR [stderr] (http--127.0.0.1-8080-2)      ... 51 more
      
      
      



      The country converter, the city converter is similar with country converter. Converter class is from the Seam 3 faces module.


      @FacesConverter("countryConverter")
      @RequestScoped
      public class CountryConverter extends Converter<Country> {
      
           @Inject
           EntityManager em;
      
           @Override
           public Country toObject(UIComponent comp, String value) {
                if (value == null || "".equals(value.trim())) {
                     return null;
                }
                return em.find(Country.class, Long.valueOf(value));
           }
      
           @Override
           public String toString(UIComponent comp, Country value) {
                if (value == null) {
                     return "";
                }
                return value.getId().toString();
           }
      
      }
      
      



      the partial page code.


                                    <p:input id="addressCountry"
                                         label="#{messages['Addressee.Country']}">
                                         <h:selectOneMenu id="input"
                                              value="#{addresseeEdit.selectedCountry}">
                                              <f:selectItems var="counVar" itemLabel="#{counVar.name}"
                                                   value="#{countries}" />
                                              <f:converter converterId="countryConverter" />
                                              <a4j:ajax event="change" render="cityPortSelector"
                                                   execute="@this" />
                                         </h:selectOneMenu>
                                    </p:input>
                                    <a4j:outputPanel id="cityPortSelector">
                                         <ui:fragment rendered="#{addresseeEdit.selectedCountry ne null}">
                                              <p:input id="city" label="#{messages['Addressee.City']}">
                                                   <h:selectOneMenu id="input"
                                                        value="#{addresseeEdit.currentAddressee.city}">
                                                        <f:selectItems var="cVar" itemLabel="#{cVar.name}"
                                                             value="#{addresseeEdit.cities}" />
                                                        <f:converter converterId="cityConverter" />
                                                        <a4j:ajax event="change" render="cityAreaCodeSelector"
                                                             execute="@this" />
                                                   </h:selectOneMenu>
                                              </p:input>
      




      How to overcome the barrier?


      Any help is appreciated.