5 Replies Latest reply on Nov 20, 2008 6:33 PM by hvico

    s:convertEntity and toString method

    hvico

      Hello SEAM community!


      First of all I must say I am a SEAM newbie, so maybe I am just misusing things. I am using SEAM 2.0.2.GA


      The thing is, I want to dinamically generate a radiobutton selection according to the addresses of a person (Person entity has a OneToMany relationship with Address entity).


      So this is my code:


      xhtml:



      <h:selectOneRadio value="#{personHome.instance.address}"  required="true" >
              <s:selectItems value="#{adressList.resultList}" var="adress" label="#{adress.street}" />
              <s:convertEntity />
      </h:selectOneRadio>



      This works perfectly, but the problem appears when I add a toString() method to my Address entity (I add this method to use it somewhere else, it is not related to this radiobuttons). It seems that s:convertEntity fails when I define that method.


      This is my address entity's toString method:



      /**
      * @return
      * @see java.lang.String#toString()
      */
      public String toString() {
              return streetNumber + " " + street + " - " + city + "/" + country;
      }   






      This is the stack trace of the exception I get:


      java.lang.IllegalArgumentException: Cannot convert 1234 TestAddress - TestCity/TestCountry of type class org.domain.entity.Direccion to class org.domain.entity.Direccion_$$_javassist_3
              at org.jboss.el.lang.ELSupport.coerceToType(ELSupport.java:358)
              at org.jboss.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:46)
              at org.jboss.seam.el.SeamExpressionFactory.coerceToType(SeamExpressionFactory.java:70)
              at com.sun.faces.renderkit.html_basic.RadioRenderer.renderOption(RadioRenderer.java:87)
              at com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:146)
              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.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:103)
              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.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:79)
              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:199)
              at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:194)
              at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
              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 javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)



      Any suggestion?


      Many thanks!

        • 1. Re: s:convertEntity and toString method
          hvico

          Sorry, I think that toString has nothing to do with this problem. Someway it worked it a test case, but now it does not work and I get the same exception (but of course I do not see the object in a human-readable way because I removed the toString method).


          I have no problems when a define a new Person, the radiobuttons appear perfectly. The problem occurs when I try to edit a person, then I get the exception listed above.


          Thanks!

          • 2. Re: s:convertEntity and toString method
            hvico

            The exception which I posted also is not traslated (i forgot to traslate the entity name to english in my first post). The exception would be this one:



            java.lang.IllegalArgumentException: Cannot convert 1234 TestAddress - TestCity/TestCountry of type class org.domain.entity.Address to class org.domain.entity.Address_$$_javassist_3
                    at org.jboss.el.lang.ELSupport.coerceToType(ELSupport.java:358)
                    at org.jboss.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:46)
                    at org.jboss.seam.el.SeamExpressionFactory.coerceToType(SeamExpressionFactory.java:70)
                    at com.sun.faces.renderkit.html_basic.RadioRenderer.renderOption(RadioRenderer.java:87)
                    at com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:146)
                    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.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:103)
                    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.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:79)
                    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:199)
                    at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:194)
                    at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                    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 javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)


            • 3. Re: s:convertEntity and toString method
              v.masterov

              There is an attempt to cast Address to proxy class of Address. Is address have lazy association on Person entity ? Please, show code of the Person class. Whether has ancestor at the class Address ?

              • 4. Re: s:convertEntity and toString method
                hvico

                Yes, that was my problem. The association was mapped as lazy. Changed it to eager and now it works.


                Thank you very much!


                Can you please explain why can't I use a lazy association with this radio buttons? Because it seems to work fine using a combo box (selectOneMenu)


                Thanks again!

                • 5. Re: s:convertEntity and toString method
                  hvico

                  Horacio Vico wrote on Nov 16, 2008 22:09:


                  ...
                  Can you please explain why can't I use a lazy association with this radio buttons? Because it seems to work fine using a combo box (selectOneMenu)

                  Thanks again!


                  Anyone? Thanks!