1 Reply Latest reply on Jun 16, 2010 2:08 AM by shane lee

    Form wizard and conversation scope issue

    shane lee Newbie

      Environment: Seam 2.2.0.GA JDK 1.6 JBOSS 5.1.0.GA Hibernate 3.3.0.GA


      Im having an issue setting up a simple form wizard.
      Steps are:


       * Screen #1: submit inquiry form detail
       * Screen #2: add attachment(s) 
       * Screen #3: confirm attachment list



      Im on screen 2 and when i add attachment to inquiry, they are not been stored. I am using a stateful session bean, which default scope is conversation for my action class.


      I have a radio button on screen one adding inqiry, isAddAttachments. If true then i go to screen two and upload as many attachments as i want before submitting. I outject newInquiry to conversation scope so i take its stored there until i end the conversation. problem is every time i add an attachment the size of the list is one.


      Why is that? Is it a problem around seam component newAttachment or the way im storing my newInquiry context variable?


      Snippet Code for action class is:



      @Stateful
      @Name(value="inquiry")
      public class InquiryAction implements Inquiry {
          
          @org.jboss.seam.annotations.In
          @Out
          private inquiry.model.Inquiry newInquiry;
          
          @In(required=false)
          Attachment newAttachment;
          
          @Logger private Log log;
          @In
          private Renderer renderer;
          @In
          private EntityManager entityManager;
          
          @org.jboss.seam.annotations.In
          private org.jboss.seam.faces.FacesMessages facesMessages;
          
          @Begin
          public String addInquiry(){
              if(newInquiry.getEmail().trim().equals(newInquiry.getConfirmEmail().trim())){
                      //store pdf in document
                      byte[] pdf = this.createPDF();
                      newInquiry.setPdfDocument(pdf);
                      if(!newInquiry.isAddAttachments()){
                          entityManager.persist(newInquiry);
                          this.sendEmail();
                          facesMessages.add("Successfully submitted web inquiry form");
                      }
                      return "success";
              }else{
                  facesMessages.add("Email addresses do not match");
                  return null;
              }
          }
          
          @End
          public void save(){
              entityManager.persist(newInquiry);
              this.sendEmail();
              facesMessages.add("Successfully submitted web inquiry form");
          }
          
          public void addAttachment(){
              newInquiry.getAttachments().add(newAttachment);
              facesMessages.add("Added attachment to inquiry form {0}",newAttachment.getFileName());
          }
          
          @End
          public String cancel(){
              return "/home.xhtml";
          }



      Inquiry entity is:



      @Entity
      @Name(value = "newInquiry")
      public class Inquiry  implements Serializable{
          
          /**
           * 
           */
          private static final long serialVersionUID = 1L;
          private long id;
          private String question;
          private String entityNumber;
          private String entityName;
          private Title title;
          private String givenName;
          private String familyName;
          private String telephoneNumber;
          private String email;
          private QuestionType questionType;
          private String timeToCall;
          private String confirmEmail;
          private boolean addAttachments;
          private byte[] pdfDocument;
          private Set<Attachment> attachments = new HashSet<Attachment>(0);
          @Embedded
          @AttributeOverrides( {
                  @AttributeOverride(name="countryCode", column = @Column(name="countryCode")) } )
          private Address address = new Address();
          
      
          public Inquiry(){
          }
          
          @Id
          @GeneratedValue
          public long getId() {
              return id;
          }
          
          
          public void setId(long id){
              this.id = id;
          }
          
          @Column(name = "pdfDoc")
          @Basic(fetch = FetchType.LAZY)
          public byte[] getPdfDocument() {
              return pdfDocument;
          }
          
          public void setPdfDocument(byte[] pdfDocument) {
              this.pdfDocument = pdfDocument;
          }
          
          @Transient
          public boolean isAddAttachments() {
              return addAttachments;
          }
          
          public void setAddAttachments(boolean addAttachments) {
              this.addAttachments = addAttachments;
          }
          
          @NotNull
          @Column(nullable = false)
          public String getTimeToCall() {
              return timeToCall;
          }
          
          public void setTimeToCall(String timeToCall) {
              this.timeToCall = timeToCall;
          }
          
          @Enumerated(EnumType.STRING)
          public QuestionType getQuestionType() {
              return questionType;
          }
          
          public void setQuestionType(QuestionType questionType) {
              this.questionType = questionType;
          }
          
          
          @Column(length = 5000)
          public String getQuestion() {
              return question;
          }
      
          public void setQuestion(String question) {
              this.question = question;
          }
      
          @Column(length = 9, nullable = false)
          @NotNull
          public String getEntityNumber() {
              return entityNumber;
          }
      
          public void setEntityNumber(String entityNumber) {
              this.entityNumber = entityNumber;
          }
      
          public String getEntityName() {
              return entityName;
          }
      
          public void setEntityName(String entityName) {
              this.entityName = entityName;
          }
      
          @Enumerated(EnumType.STRING)
          public Title getTitle() {
              return title;
          }
      
          public void setTitle(Title title) {
              this.title = title;
          }
      
          @NotNull
          public String getGivenName() {
              return givenName;
          }
      
          public void setGivenName(String givenName) {
              this.givenName = givenName;
          }
      
          @NotNull
          public String getFamilyName() {
              return familyName;
          }
      
          public void setFamilyName(String familyName) {
              this.familyName = familyName;
          }
      
          @NotNull
          @Column(name = "phoneNo")
          public String getTelephoneNumber() {
              return telephoneNumber;
          }
      
          public void setTelephoneNumber(String telephoneNumber) {
              this.telephoneNumber = telephoneNumber;
          }
      
          @Email()
          @NotNull
          public String getEmail() {
              return email;
          }
      
          public void setEmail(String email) {
              this.email = email;
          }
          
          @Transient
          public String getConfirmEmail(){
              return this.confirmEmail;
          }
          
          public void setConfirmEmail(String email) {
              this.confirmEmail = email;
          }
          
          @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "inquiry")
          public Set<Attachment> getAttachments() {
              return attachments;
          }
      
          public void setAttachments(Set<Attachment> attachments) {
              this.attachments = attachments;
          }
      
          public Address getAddress() {
              return address;
          }
      
          public void setAddress(Address address) {
              this.address = address;
          }



      Attachment screen snippet is:




       <h:form enctype="multipart/form-data" id="attachmentForm" styleClass="edit">
          <rich:panel>
                  <f:facet name="header">General Inquiry form - Attachments</f:facet>
                  
                  <s:decorate id="descField" template="layout/edit.xhtml">
                      <ui:define name="label">Description of Document</ui:define>
                      <h:inputText id="description"
                                    value="#{newAttachment.description}"/>
                  </s:decorate>
                  <s:decorate id="fileUploadDecoration" template="layout/edit.xhtml">
                               <ui:define name="label">Pathname</ui:define>
                               <s:fileUpload id="file" 
                                          data="#{newAttachment.doc}"
                                          contentType="#{newAttachment.fileContentType}"
                                          fileName="#{newAttachment.fileName}"
                                          fileSize="#{newAttachment.fileSize}" />
                          </s:decorate>
                          
                           <div style="clear:both">
                      <span class="required">*</span>
                      required fields
                  </div>
                  
                  </rich:panel>
                  
                  <div class="actionButtons">
                          <h:commandButton value="Upload" 
                                     action="#{inquiry.addAttachment}"/>
                          <h:commandButton value="Next" 
                                     action="#{inquiry.save}"/>
                     </div>
                     
                     <s:link view="/attachmentList.xhtml" value="Attachment Summary"/>
      
                  
                  </h:form>






      Thanks,
      Shane.