6 Replies Latest reply on Sep 12, 2007 11:53 AM by Cody Lerum

    New User Lazy Load Question

    Cody Lerum Apprentice

      Hello.

      I'm just getting my start in the seam framework. I've used the seam-gen to setup the base of my project.

      I have a basic site up where new users and register and login. What I'm trying to add now is the ability for users to add phone numbers to their account. I want to have the ability to have multiple phone number records per user (mobile, office, home, etc) thus it's set as a OneToMany

      @Entity
      @Name("user")
      @Scope(SESSION)
      public class User implements Serializable
      {
      
       private static final long serialVersionUID = -5311104884213351414L;
       private long id;
       private String username;
       private String password;
       private String firstname;
       private String lastname;
       private List <Phone> phones;
      
       public User() {}
      
       @Id @GeneratedValue
       public long getId()
       {
       return id;
       }
      
       public void setId(long id)
       {
       this.id = id;
       }
      
      
       @Length(min=5, max=50)
       public String getUsername()
       {
       return username;
       }
       public void setUsername(String username)
       {
       this.username = username;
       }
      
       public String toString()
       {
       return "User(" + username + ")";
       }
      
       @NotNull
       @Length(min=5, max=15)
       public String getPassword()
       {
       return password;
       }
      
       public void setPassword(String password)
       {
       this.password = password;
       }
      
       @NotNull
       @Length(max=100)
       public String getFirstname()
       {
       return firstname;
       }
       public void setFirstname(String firstname)
       {
       this.firstname = firstname;
       }
      
       @NotNull
       @Length(max=100)
       public String getLastname()
       {
       return lastname;
       }
       public void setLastname(String lastname)
       {
       this.lastname = lastname;
       }
      
       @OneToMany(mappedBy="user")
       public List <Phone> getPhones() {
       return phones;
       }
      
       public void setPhones(List <Phone> phones) {
       this.phones = phones;
       }
      
      
      }
      

      @Entity
      @Name("phone")
      @Scope(SESSION)
      public class Phone implements Serializable
      {
      
       private static final long serialVersionUID = -8926240091475742891L;
      
       private long id;
       private String name;
       private String number;
       private User user;
      
       public Phone () {}
      
       @Id @GeneratedValue
       public long getId()
       {
       return id;
       }
      
       public void setId(long id)
       {
       this.id = id;
       }
       @NotNull
       @Length(min=2, max=15)
       public String getName()
       {
       return name;
       }
      
       public void setName(String name)
       {
       this.name = name;
       }
       @NotNull
       @Length(min=10, max=50)
       public String getNumber()
       {
       return number;
       }
      
       public void setNumber(String number)
       {
       this.number = number;
       }
      
       @ManyToOne
       public User getUser()
       {
       return user;
       }
      
       public void setUser(User user)
       {
       this.user = user;
       }
      }
      


      What I'm trying to get working is just a list of the current logged in users phone records.
      <f:subview id="phones"
       rendered="#{!empty(phones)}">
      <p>You have the following Phone Numbers Stored:</p>
      <h:dataTable value="#{user.phones}" var="id">
       <h:column>
       <h:outputText value="#{phones.number}"/>
       </h:column>
      </h:dataTable>
      </f:subview>


      I'm guessing it's something thats wrong in my ui code, but I don't see any examples that have simple mapped tables. Can someone point me in the right direction? How would I call and present the List of phones from my page?