0 Replies Latest reply on Nov 9, 2011 6:57 PM by gebuh

    Seam file upload not uploading without persistance to db

    gebuh

      My use case is:
      user uploads an excel file
      I parse that file into an entityBean list
      validate the data and save it to a db table.


      I can upload a file and save it to the db as a lob.  But I can't upload the file and manipulate it first.  It appears that the data remains null.
      uploadView.xhtml:



      <h:form enctype="multipart/form-data">
      <s:fileUpload id="file"     acceptedTypes ="#{acType}"
                               data="#{uploadAttachment.data}"                              
                              contentType="#{uploadAttachment.contentType}"
                              fileName="#{uploadAttachment.name}"
                              fileSize="#{uploadAttachment.size}"
                          /> 
      <a:commandButton value="Upload" action="#{uploadAttachment.upload()}" reRender="vw"/>
      
      



      components.xml:



      <web:multipart-filter create-temp-files="false"
                            max-request-size="1000000" 
                            url-pattern="*.seam" />




      upload entity:



      @Name("uploadAttachment")
      @Scope(ScopeType.SESSION)
      public class UploadAttachment implements Serializable {
           private String name;
           private long size;
           private String contentType;
           private byte[] data;  //this is always null
      
           public boolean upload(){
                log.debug("getting some data " + this.getName());
                return true;
           }
      ...various getters and setters
      



      So I tried using rich:fileUpload. 
      uploadView.xhtml:



      <rich:fileUpload fileUploadListener="#{uploadAttachment.listener}"
                      id="upload"
                      immediateUpload="false"
                      acceptedTypes="#{acType}" >
                      <a:support event="onuploadcomplete" reRender="upPnl" />  
                  </rich:fileUpload>



      added this method to upload attachemt file:



       public void listener(UploadEvent event) throws Exception{
                 log.debug("creating a new attachment object");
                  UploadItem item = event.getUploadItem();
                  this.data = item.getData();
                  this.size = this.data.length;  //TODO HANDLE NULLS!!!!!!!!!!!!!!!!!
                  this.name =item.getFileName();
                  this.contentType = item.getContentType();
               }





      Initially this wouldn't work either data was still null), until I added:



      <init-param>
       <param-name>createTempFiles</param-name>
       <param-value>false</param-value>
       </init-param>


      to web.xml.  I'm able to upload files now, but why would I need this?  Shouldn't the filter in components.xml cover this?


      This still doesn't allow me to upload files using the Seam component though.  Is there something else I'm missing?