3 Replies Latest reply on Nov 10, 2008 9:58 PM by Ln Larouche

    Problem to restore state of @Convert Component

    Marcos Sousa Newbie

      Hello,


      I'm try to create a converter using Seam @Convert Framework to my product entity, but when my page make a request I got this error:


      21:25:08,074 WARN  [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@33c690) threw exception
      java.lang.IllegalStateException: com.marcossousa.converters.ProductConverter
           at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:90)
           at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1414)
           at javax.faces.component.UIOutput.restoreState(UIOutput.java:215)
           at javax.faces.component.UIInput.restoreState(UIInput.java:1233)
           at javax.faces.component.html.HtmlSelectOneListbox.restoreState(HtmlSelectOneListbox.java:859)
           at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1141)



      My Converter code class is:


      package com.marcossousa.converters;
      
      import javax.faces.application.FacesMessage;
      import javax.faces.component.UIComponent;
      import javax.faces.context.FacesContext;
      import javax.faces.convert.ConverterException;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityNotFoundException;
      
      import com.marcossousa.entity.Product;
      import org.jboss.seam.Component;
      
      
      public class ProductConverter implements javax.faces.convert.Converter {
      
           public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
               entityManager.joinTransaction();
               
               try {
                     Integer id = new Integer(new Integer( arg2 ));
                      if (id == null || id.equals(0)) {
                           return null;
                      }
                      return entityManager.find(Product.class, id);
                } catch( NumberFormatException nfe ) {                
                     throw new ConverterException(new FacesMessage("Invalid product id"));
                } catch (EntityNotFoundException e) {
                     throw new ConverterException(new FacesMessage("Product not found"));
                }
              
           }
      
           public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                if (arg2 == null) {
                     return null;
                } else if (arg2 instanceof Product) {
                     Product u = ((Product) arg2);
                     return String.valueOf(u.getProductid());
                } else {
                     throw new ConverterException("Invalid product type");
                }
           }
      }



      ps: I'm using Seam 2.0.2 RC1.


      Thanks for help!


        • 1. Re: Problem to restore state of @Convert Component
          Felipe Pastenes Newbie

          Hi,
          I fixed this problem by using @Scope(ScopeType.PAGE) in Converter Component, for example:


          @Name("myConverter")
          @BypassInterceptors
          @Scope(ScopeType.PAGE)
          @Converter
          public class MyConverter implements javax.faces.convert.Converter, Serializable ...
          



          thus there is no problem with restore store in Ajax requests

          • 2. Re: Problem to restore state of @Convert Component
            Mikael Andersson Master

            Hi


            I just ran into this problem myself while converting my old Converters from plain JSF to using Seam annotations.


            Can someone explain why this issue arise?


            Also are there side effects when using the PAGE ScopeType?


            I'm kind of reluctant to just doing this without understanding the cause (difference plain JSF converter and Seam annotated ones).



            Many thanks,
            Micke

            • 3. Re: Problem to restore state of @Convert Component
              Ln Larouche Newbie

              Hi,


              I had the exact same problem, but when I tried your solution, I got another error:


              Exception during request processing:
              Caused by javax.servlet.ServletException with message: La valeur doit être convertible en une énumération ou depuis lénumération, mais aucune classe dénumération nest fournie. In English, this means something like Value must me convertible to an enum or from an enum , but no enum class is offered.


              Here's the whole stack trace:


              15:42:48,930 ERROR [STDERR] 10-Nov-2008 3:42:48 PM com.sun.facelets.FaceletViewHandler handleRenderException
              SEVERE: Error Rendering View[/details.xhtml]
              javax.faces.FacesException: javax.faces.convert.ConverterException: La valeur doit être convertible en une énumération ou depuis lénumération, mais aucune classe dénumération nest fournie
                   at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:675)
                   at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:650)
                   at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:681)
                   at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:650)
                   at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:543)
                   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                   at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                   at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                   at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
                   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                   at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:51)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   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:56)
                   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.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
              Caused by: javax.faces.convert.ConverterException: La valeur doit être convertible en une énumération ou depuis lénumération, mais aucune classe dénumération nest fournie
                   at javax.faces.convert.EnumConverter.getAsString(EnumConverter.java:184)
                   at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
                   at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:322)
                   at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
                   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                   at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:190)
                   at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
                   at org.jboss.seam.ui.renderkit.ValidateAllRendererBase.doEncodeChildren(ValidateAllRendererBase.java:33)
                   at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                   at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:186)
                   at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
                   at org.jboss.seam.ui.renderkit.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:146)
                   at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                   at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                   at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:347)
                   at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:342)
                   at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                   at org.richfaces.renderkit.html.SimpleTogglePanelRenderer.encodeChildren(SimpleTogglePanelRenderer.java:208)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                   at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                   at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                   at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
                   at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
                   at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:124)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComp




              I'm using Seam 2.1.


              If anyone has a clue, please let me know!