1 Reply Latest reply on Sep 16, 2008 1:25 PM by mteichmann.mark.teichmann.info-ag.de

    How to bind selectManyListBox to Seam Entity with special boundary conditions?

    mteichmann.mark.teichmann.info-ag.de

      I have three tables Person, Team and CollectionPersonTeam. When a person is member of a team then a new entry in table CollectionPersonTeam is generated. The seamgen generated XHTML creates rich:tabs with subviews for this but I need to fill in these values in one single page if possible.


      In my generated entities the Person entity looks as follows:



      @Entity
      @Table(name = "Person", schema = "dbo")
      
      public class Person implements java.io.Serializable {
      
      private Set<CollectionPersonTeam> collectionPersonTeams = new HashSet<CollectionPersonTeam>(0);
      
           @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "person")
           public Set<CollectionPersonTeam> getCollectionPersonTeams() {
                return this.collectionPersonTeams;
           }
      
           public void setCollectionPersonTeams(
                     Set<CollectionPersonTeam> collectionPersonTeams) {
                this.collectionPersonTeams = collectionPersonTeams;
           }



      My XHTML roughly contains this:



      <s:decorate id="teamDecoration" template="layout/edit.xhtml" for="teamListBox">
                   <ui:define name="label">#{messages['TEAM']}</ui:define> 
             <h:selectManyListbox value="#{personHome.instance.collectionPersonTeams}" id="teamListBox">
                  <s:selectItems value="#{teamList.resultList}" var="team" label="#team.name}" />
             </h:selectManyListbox>
      </s:decorate>



      Now I am trying to build an XHTML page which contains a selectManyListBox where I can select many teams from table Team. These teams now should end up in new entries in table CollectionPersonTeam after using entityHome.persist from my Person object.
      It is obvious that the code above cannot work because I cannot put a team object into a field of type collectionPersonTeam.

      Should I go for a custom converter or should I use an additional bean to hold the values and let it persist my person entity or what else could I do? I tried building a converter but ended in several problems which I can show in more detail if using a converter really is an option here.