1 Reply Latest reply on Jan 2, 2013 9:29 AM by kpiwko

    Elements in collection are lost

    iapazmino

      Hi,

       

      I've a simple test which loads some info during pre-render view phases and then send this info when submiting. The object where this info is loaded is produced at the backing bean

       

      @Produces 
      @Named 
      private Email newEmail = new Email();
      

       

      and the info is loaded at the two pre-render view phase listeners

       

      newEmail.addDestinatary(destinatary);
      ...
      newEmail.setSubject(emailTemplate.getSubject());
      newEmail.setText(emailTemplate.getText());
      

       

      When the submit button is clicked the newEmail object still holds the subject and the text values but the list is empty

       

      The Email class is a very simple entity holding a list and two String fields

       

      @Entity
      public class Email implements Serializable {
      
          private static final long serialVersionUID = 1L;
      
          @Id
          @GeneratedValue
          private long pk;
      
          @OneToMany
          private List<Customer> destinataries;
          private String subject;
          private String text;
      
          public Email() {
              this(null, null);
          }
          
          public Email(final String subject, final String text) {
              this.destinataries = new ArrayList<Customer>();
              this.subject = subject;
              this.text = text;
          }
      
          public long getPk() {
              return pk;
          }
      
          public void setPk(long pk) {
              this.pk = pk;
          }
      
          public List<Customer> getDestinataries() {
              return destinataries;
          }
      
          public void setDestinataries(List<Customer> Destinataries) {
              this.destinataries = Destinataries;
          }
          
          public void addDestinatary(final Customer destinatary) {
              destinataries.add(destinatary);
          }
      
          public String getSubject() {
              return subject;
          }
      
          public void setSubject(String subject) {
              this.subject = subject;
          }
      
          public String getText() {
              return text;
          }
      
          public void setText(String text) {
              this.text = text;
          }
      
          @Override
          public String toString() {
              StringBuilder builder = new StringBuilder();
              builder.append("Email [to=").append(destinataries).append(", subject=")
                      .append(subject).append("]");
              return builder.toString();
          }
      
      }
      

       

      Why could this be happening?