3 Replies Latest reply on Sep 17, 2009 2:24 PM by Tamas Malatinszki

    Capture all inputs related to OneToMany relationship in a single form

    Evelyn Jeba Newbie
      I have a simple requirement where I need to capture all information regarding my OneToMany relationship in a single form. How do I generate a .xhtml page to handle creation / modification of entities.

      import java.util.List;

      @Entity
      @Table(name = "person")
      public class Person implements java.io.Serializable {

          @Id
          @GeneratedValue(strategy = IDENTITY)
          @Column(name = "id")
          private Integer id;

          private String name;

          @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
          private List<Email> emails;

          public Person() {
          }

          public Integer getId() {
              return id;
          }

          public final void setId(final Integer id) {
              this.id = id;
          }

          public String getName() {
              return name;
          }

          public final void setName(final String name) {
              this.name= name;
          }

          public final List<Email> getEmails() {
              return emails;
          }

          public final void setEmails(final List<Email> emails) {
              this.emails= emails;
          }
      }

      Email.java just has a single member variable emailAddress.

      I would like the form to have a field for Person.name and 2 additional fields for Email.emailAddress.
      How do I generate a form which will dynamically bind my form inputs to the PersonHome, EmailHome classes. I don't want to use the OneToMany TAB which is generated for adding emails.

      Appreciate any pointers / help on this topic