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

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

    hantsy

      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.

        • 1. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
          ssachtleben.ssachtleben.gmail.com

          I had the same issue before and changed the Mojarra version back to 2.0.3-b05. Now ajax works fine as it should.


          Try to drop jsf-impl-2.0.3-b05.jar here:
          /your/path/jboss-as-web-7.0.1.Final/modules/com/sun/jsf-impl/main


          and modify module.xml:


          <module xmlns="urn:jboss:module:1.0" name="com.sun.jsf-impl">
              <dependencies>
                  <module name="javax.faces.api"/>
                  <module name="javaee.api"/>
                  <module name="javax.servlet.jstl.api"/>
                  <module name="org.apache.xerces" services="import"/>
                  <module name="org.apache.xalan" services="import"/>
              </dependencies>
          
              <resources>
                  <resource-root path="jsf-impl-2.0.3-b05.jar"/>
              </resources>
          </module>



          • 2. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
            hantsy

            I replaced it with 2.0.6 FCS, but got the same exception.
            I must use 2.0.3-b05?

            • 3. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
              ssachtleben.ssachtleben.gmail.com

              I think yes. At least 2.0.3-b05 is the only working version for me.


              I think the ajax bug is fixed in the current version, but that one doesn't invoke s:viewAction methods.

              • 4. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                hantsy

                also the same problem....
                Did u use the Seam faces InputContainer to wrap the input field?

                • 5. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                  ssachtleben.ssachtleben.gmail.com

                  Ah sorry fail I'm using Mojarra 2.0.2 (FCS b10). Please try this version.


                  Here is an example:


                  <components:input id="search-dec-brand"
                       labelText="#{bundles.messages['inseration.refinesearch.Brand']}"
                       labelStyle="width: 55px" useSpacer="true">
                       <h:selectOneMenu id="search-brand"
                            value="#{inserationAgent.brand}" style="width: 200px">
                            <f:selectItem
                                 itemLabel="#{bundles.messages['inseration.refinesearch.Select']}"
                                 itemValue="#{null}" />
                            <f:selectItems value="#{inserationAgent.brands}" var="brand"
                                 itemLabel="#{brand.name}" itemValue="#{brand}" />
                            <a4j:ajax event="change"
                                 render="searchForm_results_resultPanel" execute="@this"
                                 listener="#{inserationAgent.find}" />
                            <f:converter converterId="inserationBrandConverter" />
                       </h:selectOneMenu>
                  </components:input>



                  As you see here. AJAX works awesome.

                  • 6. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                    hantsy

                    Exactly, after replaced with this version, it worked well.


                    Thank you every much.

                    • 7. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                      ssachtleben.ssachtleben.gmail.com

                      You are welcome.


                      I have blogged about that issue also.


                      Lets cross fingers for an upcoming bug-free Mojarra version.

                      • 8. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                        hantsy

                        Your website looks very good.


                        But our before project is based on Seam2.2 and richfaces 3.3, the generated html by richfaces is very terrible, we used many rich components, such as toolbar, extendedDataTable, tree, drag and drop, context menu...so the cusotmer did not satisfy the page performance.


                        Different from ur website, we have many complex insert and update operations, this is an internal web system, not a website.


                        I have been doing some research on Seam 3 in these two weeks, if I can not overcome the barriers I encountered in these days, I think we will keep on Seam 2...and replace the rich components with plain standard jsf component and pure client solution(HTML and javascript).


                        • 9. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                          hantsy

                          I have tried in JBoss 7.0.2Final(jsf upgraded to 2.1.3FCS), I got a new expectipn.



                          16:29:49,498 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                          16:30:15,876 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                          16:30:18,176 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                          
                          

                          • 10. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                            hantsy

                            The dropdown ajax does not work at all.

                            • 11. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                              lightguard

                              Hantsy, we know there are AJAX problems, Sebastian mentioned trying 2.0.2 and seeing what happens there.

                              • 12. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                                lightguard

                                hantsy bai wrote on Sep 26, 2011 04:32:


                                I have tried in JBoss 7.0.2Final(jsf upgraded to 2.1.3FCS), I got a new expectipn.


                                16:29:49,498 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                                16:30:15,876 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                                16:30:18,176 INFO  [com.telopsys.siorc.exception.handler.GeneralExceptionHandler] (http--127.0.0.1-8080-11) Exception logged by seam-catch catcher: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
                                
                                




                                Looks to me like that's an error with your application. as you can see in the log it's an INFO from a handler you created. If you want more info try debugging the handler you created and  see what the problem is.

                                • 13. Re: Exception when use customsized Converter and Ajax in Seam 3 application.
                                  hantsy

                                  I have said, it worked well when use 2.0.2...


                                  I only want to try the newest JBoss 7.0.2Final yesterday, I got the same exception. I do not know it was caused by Richfaces or the compatibility between Glassfish jsf impl and Richfaces.


                                  I will replace the a4j tag with pure jsf ajax tag and have a try.