5 Replies Latest reply on Mar 12, 2008 10:55 AM by Jerome Jourdain

    multiple file upload (s:fileUpload)

    Jerome Jourdain Newbie

      Hi all,

      I'm trying to upload several files using seam and facelets.
      I've succeeded to upload a single file thanks to this link: http://linuxbeans.blogspot.com/2007/10/image-handling-in-seam-apps-part-ii.html
      however, I failed to do the same with several files.

      here is my code:

          <component class="org.jboss.seam.web.MultipartFilter">
              <property name="createTempFiles">true</property>
              <property name="maxRequestSize">1000000</property>

      //Action bean
      package com.test.business.action;
      import java.util.ArrayList;
      import java.util.List;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      import com.cat.lc.nfp.business.model.UploadFile;
      public class TestUploadAction {
        Log log;
        private static final String accept = "text/plain,text/xml,application/xml,application/vnd.ms-excel";
        int fileNumber = 5;
        private List<UploadFile> files;
        public List<UploadFile> getFiles() {
          return files;
        public void setFiles(List<UploadFile> files) {
          this.files = files;
        public void setFileNumber(int fileNumber) {
          this.fileNumber = fileNumber;
        public void upload(){
        public void initialize(){    
          files = new ArrayList<UploadFile>(fileNumber);
          for (int i = 0; i < fileNumber; i++) {
            files.add(new UploadFile(i));
        private void display(){    
        UploadFile file;
        for (int i = 0; i < files.size(); i++) {
          log.debug("########### processing file #0", i);
          file = files.get(i);
            log.debug("contentType:#0", file.getContentType());
            log.debug("fileName:#0", file.getName());
            log.debug("title:#0", file.getTitle());
            log.debug("size:#0", file.getSize());               
        public int getFileNumber() {
          return fileNumber;
        public String getAccept() {
          return accept;

      import java.io.Serializable;
      import org.jboss.seam.annotations.Name;
      |public class UploadFile implements Serializable{
           private int id;
           private byte[] data;
           private String contentType;    
           private String name;    
           private String title;    
           private int size;
           public UploadFile(){
           public UploadFile(int id){
           public byte[] getData() {
                return data;
           public void setData(byte[] data) {
                this.data = data;
           public String getContentType() {
                return contentType;
           public void setContentType(String contentType) {
                this.contentType = contentType;
           public String getName() {
                return name;
           public void setName(String name) {
                this.name = name;
           public String getTitle() {
                return title;
           public void setTitle(String title) {
                this.title = title;
           public int getSize() {
                return size;
           public void setSize(int size) {
                this.size = size;
           public int getId() {
                return id;
           public void setId(int id) {
                this.id = id;

      //View (.xhtml)
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        <ui:define name="body">
            value="#{messages['data.fileUpload.label.title']}" /></h1>
          <br />
          <br />
          <h:form enctype="multipart/form-data">
            <a:outputPanel id="table">
              <table border="0">
                    <th><h:outputText value="Title" /></th>
                    <th><h:outputText value="File" /></th>
                  <a:repeat value="#{testUploadService.files}" var="file">
                          <h:inputText value="#{file.title}" immediate="true" size="50" maxlength="80"/>                    
                        <s:fileUpload data="#{file.data}"
                                      fileSize="#{file.size}" size="40"
                                      maxlength="80" />
                      <td colspan="2" style="text-align: center;">
                          <a:commandButton value="Upload" action="#{testUploadService.upload}"/>                    
                          <a:commandButton value="Cancel" type="reset"/>
            <rich:messages />

      The problem is that the files uploaded are usually empty!

      any idea?

      thx in advance.