0 Replies Latest reply on Oct 6, 2008 9:54 AM by Mikael Andersson

    Restore state problem with AtConverter Annotation

    Mikael Andersson Master

      Hi


      When converting some converters from plain old JSF (faces-config) to Seam annotated ones I've run into a problem with what seems to be restoring state.


      Tried the proposed solution of using PAGE scope for the converter found here old forum post but that didn't work.


      I have the converter setup as a Facelets converter in order to support the unit attribute.


      I'm curious about what is different when configuring the converter via Seam? Thinking it might be a bug in my code....


      My converter code:


      @Name("unitDoubleConverter")
      @Scope(ScopeType.PAGE)
      @Converter
      public class UnitDoubleConverter extends NumberConverter implements Serializable,StateHolder{
      
          /**
           * <code>serialVersionUID</code>.
           */
          private static final long serialVersionUID = 1L;
          
          private Double unit;
      
          /**
           * If unit is defined then multiply by the unit number (to get to the correct value) and pass
           * on to the @see NumberConverter class
           */
          @Override
          public Object getAsObject(FacesContext ctx, UIComponent comp, String value) {
              if(value == null){
                  return null;
              }
              value = value.trim();
              if(value.length() == 0){
                  return null;
              }
              
              Object obj = super.getAsObject(ctx, comp, value);
              
              Double theDouble = new Double(((Number)obj).doubleValue());
              
              if(unit == null){
                  return theDouble;
              }
              
              return new Double(theDouble.doubleValue()*unit.doubleValue());
            
              
          }
          
          /**
           * If unit is defined, then divide by the unit amount and pass down to the @see NumberConverter class.
           */
          @Override
          public String getAsString(FacesContext ctx, UIComponent comp, Object value) {
                      
              String retVal = null;
              if(unit == null){
                  retVal = super.getAsString(ctx, comp, value);
              }        
              else {            
                  Number num = (Number)value;
                  retVal = super.getAsString(ctx, comp, new Double(num.doubleValue()/unit.doubleValue()) );                        
              }
              
              return retVal;
          }
          
          @Override
          public void restoreState(FacesContext context, Object state) {        
              Object values[] = (Object[]) state;
              
              super.restoreState(context, values[0]);        
              setUnit((Double)values[1]);
          }
      
          @Override
          public Object saveState(FacesContext context) {
              Object values[] = new Object[2];
              values[0] = super.saveState(context);
              values[1] = getUnit();
              
              return values;
          }
      
          public Double getUnit() {
              return unit;
          }
      
          public void setUnit(Double unit) {
              this.unit = unit;
          }
      }
      




      The exception I'm getting is this:


      2008/10/06 08:45:27,939 handling uncaught exception
      javax.servlet.ServletException: dreba.prj.limex.web.jsf.converters.UnitDoubleConverter_$$_javassist_5
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at com.jamonapi.JAMonFilter.doFilter(JAMonFilter.java:57)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
           at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
           at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
           at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
           at java.lang.Thread.run(Thread.java:619)
      2008/10/06 08:45:27,939 exception root cause
      java.lang.IllegalStateException: dreba.prj.limex.web.jsf.converters.UnitDoubleConverter_$$_javassist_5
           at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:101)
           at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1441)
           at javax.faces.component.UIOutput.restoreState(UIOutput.java:226)
           at javax.faces.component.UIInput.restoreState(UIInput.java:1235)
           at javax.faces.component.html.HtmlInputText.restoreState(HtmlInputText.java:879)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1166)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1182)
           at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:415)
           at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
           at org.jboss.seam.jsf.SeamViewHandler.restoreView(SeamViewHandler.java:93)
           at com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:316)
           at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:116)
           at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:176)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at com.jamonapi.JAMonFilter.doFilter(JAMonFilter.java:57)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
           at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
           at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
           at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
           at java.lang.Thread.run(Thread.java:619)