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

    Seam file upload not uploading without persistance to db

    gebuh Newbie

      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.

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


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

      upload entity:

      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. 

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

      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:


      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?