2 Replies Latest reply on Mar 22, 2009 7:48 PM by Horacio Vico

    Problem using selectOneRadio and selectItems using inheritance

    Horacio Vico Newbie

      First of all, disclaimer: I am just trying SEAM, and therefore my model is just a stupid example. The idea is to define some hibernate mappings, and the try RichFaces and SEAM itself. Then don't panic because I am selecting things using radio buttons which have no sense in real life (for instance selecting a pet's owner using a radio) :)



      I have the following model:



      1) Customer which is a child class of Person (by inheritance)


      2) Pet which is related to Person. Every Pet has a Person (owner), mapped as a ManyToOne relationship) like this:


             


      private Person owner;



      @ManyToOne(fetch = FetchType.EAGER)
      public Person getOwner() {
                      return owner;
      }




      Then, in Pet.xhtml which is the form I use to load new Pets I have


      <h:selectOneRadio value="#{petHome.instance.owner}"  required="false" >
                                                      <s:selectItems value="#{personList.allPerson}" var="person" label="#{person.name}"  />
                                                      <s:convertEntity />
      </h:selectOneRadio>




      Then personList.allPerson has this code:



      public List<Person> getAllPerson() {
                      return super.getEntityManager().createQuery("select person from Person person").getResultList();
      }




      I loaded a person and a customer (which is a person also by inheritance). But then I try to go to Pet.xhtml (the page with the radio buttons) and kaboom, I get this exception:




      java.lang.IllegalArgumentException: Cannot convert Person Person_1 of type class uy.edu.uas.jgenui.testapp.entity.Person to class uy.edu.uas.jgenui.testapp.entity.Customer
              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)




      I don't get it, it tries to convert the defined person into a customer, and there are no references to customer into Pet.xhtml!


      Then, if I change selectOneRadio to selectOneMenu (combo) it works perfectly right.


      Any ideas please?


      Thanks!