0 Replies Latest reply on May 5, 2008 11:10 PM by m4darasz

    Error using EntityHome.update with selectOneMenu and selectManyListbox

    m4darasz

      Hello!


      I'm getting an error while trying to update an entity through EntityHome using a JSF form containing selectOneMenu and selectManyListbox.


      The error:


      sourceId=modositProjekt:pdolgozo[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]
      sourceId=modositProjekt:pvezeto[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]




      Sorry for the Hungarian variable/entity names, I hope you will get it. The main idea that there are two entities: Project (Projekt) and Worker (Dolgozo). Each Project has a leader and several team members (tagok) which are Worker (Dolgozo) objects. I would like to select the leader with a selectOneMenu and the team members with the selectManyListbox. Right now, the edit form gets the data but I unable the make updates because of the error.


      JSF form:


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:h="http://java.sun.com/jsf/html"
                      template="layout/template.xhtml">
                             
      <ui:define name="body">
      
          <h2>Projekt modositasa</h2>
          
          <h:messages globalOnly="true" styleClass="message"/>
          
          <h:form id="modositProjekt">
               <table border="0">
                  <s:validateAll>
                    <tr>
                           <td>Projekt vezeto</td>
                       <td>
                            <h:selectOneMenu value="#{projektHome.instance.vezeto}" id="pvezeto">
                                       <s:selectItems value="#{projektvezetok}" var="pvezeto" label="#{pvezeto.username}" />
                                       <s:convertEntity/> 
                               </h:selectOneMenu>
                       </td>
                    </tr>
                    <tr>
                        <td>Projekttagok</td>
                         <td>
          
                     <h:selectManyListbox value="#{projektHome.instance.tagok}" id="pdolgozo">
                                  <s:selectItems value="#{projektdolgozok}" var="pdolgozo" label="#{pdolgozo.username}" />
                                  <s:convertEntity/> 
                          </h:selectManyListbox>
                     </td>
               </tr>
                  </s:validateAll>
              </table>
              <div class="actionButtons">
                 <h:commandButton id="modisitProjekt" value="Modositas" 
                      action="#{projektHome.update}"/>                      
              </div>
          </h:form>
          
      </ui:define>
      
      </ui:composition>



      Dolgozo class:


      @Entity
      @Name("dolgozo")
      @Table(name="dolgozok")
      public class Dolgozo implements Serializable {
           
           private static final long serialVersionUID = 1310777667340045513L;
           @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;
           private Long kulsoid;
           private String username;
           private String jelszo;
           private Byte rang;
           
           // konstruktor
           public Dolgozo() {}
           public Dolgozo(Long id)
           {
                this.id = id;
           }
           
           // equals, hash override
           @Override public boolean equals(Object obj)
           {
                if (this == obj)
                     return true;
                if (obj == null)
                     return false;
                if (getClass() != obj.getClass())
                     return false;
                final Dolgozo other = (Dolgozo) obj;
                if (id != other.id)
                     return false;
                return true;
           }
           @Override
           public int hashCode() {
                final long PRIME = 31;
                long result = 1;
                result = PRIME * result + this.id;
                return (int)result;
           }
           // getter/setter
      ...
      }
           



      Projekt class:


      @Entity
      @Name("projekt")
      @Table(name="projektek")
      public class Projekt implements Serializable {
      
           private static final long serialVersionUID = -4958586845730005066L;
           @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;
           @Length(max=40) private String nev;
           private String leiras;
           @ManyToOne private Dolgozo vezeto;
           @ManyToMany(targetEntity = Dolgozo.class, fetch =     FetchType.LAZY) 
           private List<Dolgozo> tagok;
           @OneToMany(mappedBy="projekt", targetEntity = Feladat.class, 
                          fetch =     FetchType.LAZY) 
           private List<Feladat> feladatok;
           private Date kezdet;
           private Date tervvege;
           private Date becsultvege;
           private Long bekerkoltseg;
           private Long tervbevetel;
           
           // konstruktor
           public Projekt() {}
           public Projekt(Long id, String nev, String leiras, Dolgozo vezeto, 
                               List<Dolgozo> tagok, Date kezdet, Date tervvege, Date becsultvege,
                               Long bekerkoltseg, Long tervbevetel, List<Feladat> feladatok)
           {
                this.id = id;
                this.nev = nev;
                this.leiras = leiras;
                this.vezeto = vezeto;
                this.tagok = tagok;
                this.feladatok = feladatok;
                this.kezdet = kezdet;
                this.tervvege = tervvege;
                this.becsultvege = becsultvege;
                this.bekerkoltseg = bekerkoltseg;
                this.tervbevetel = tervbevetel;
           }
           
           // equalsm hash override
           @Override public boolean equals(Object obj)
           {
                if (this == obj)
                     return true;
                if (obj == null)
                     return false;
                if (getClass() != obj.getClass())
                     return false;
                final Projekt other = (Projekt) obj;
                if (id != other.id)
                     return false;
                return true;
           }
           @Override
           public int hashCode() {
                final long PRIME = 31;
                long result = 1;
                result = PRIME * result + this.id;
                return (int)result;
           }
      
           // getter/setter
      ...
      }


      ProjektHome:


      @Name("projektHome")
      public class ProjektHome extends EntityHome<Projekt>
      {
      
          @RequestParameter 
          Long projektId;
          
          @Override
          public Object getId() 
          { 
              if (projektId==null)
              {
                  return super.getId();
              }
              else
              {
                  return projektId;
              }
          }
              
          @Override @Begin
          public void create() {
              super.create();
          }
            
      }



      When I was doing the new project form I got the very same error. That time the solution was to add an equals and hash override to the Dolgozok class. There's a similarity with the two problems but I don't know how to solve this one.


      Any ideas? Thanks!