3 Replies Latest reply on Jan 9, 2013 7:41 AM by Sudipto Desmukh

    Multiple file upload - multiple issue with af:inputFile

    Tapas Bose
      I am trying to create multiple file upload by using multiple af:inputFile component. Here is my xhtml:
      <?xml version='1.0' encoding='UTF-8'?>
      <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
          <af:document id="d1" title="Home">
            <af:form id="f1" usesUpload="true">
              <af:commandButton text="Add" immediate="true"
              <af:panelGroupLayout layout="vertical" id="pgl1" partialTriggers="cb1">
                <af:iterator value="#{viewScope.massUpload.fileComponents}" var="fileComponent"
                             id="i1" varStatus="status">
                  <af:inputFile binding="#{fileComponent}" id="if1"
                <af:commandButton text="Upload"
      and this is the managed bean:
      package com.edfx.massupload.bean;
      import java.util.ArrayList;
      import java.util.List;
      import javax.faces.event.ActionEvent;
      import oracle.adf.view.rich.component.rich.input.RichInputFile;
      import oracle.stellent.ridc.IdcClientException;
      import org.apache.myfaces.trinidad.model.UploadedFile;
      public class MassUploadBean {
          private List<RichInputFile> fileComponents = new ArrayList<RichInputFile>();
          private List<UploadedFile> files = new ArrayList<UploadedFile>();
          public MassUploadBean() {
          public void add(ActionEvent event) {   
              fileComponents.add(new RichInputFile());
          public void upload(ActionEvent event) throws IdcClientException {
              for(UploadedFile file : files) {
          public void setFiles(List<UploadedFile> files) {
              this.files = files;
          public List<UploadedFile> getFiles() {
              return files;
          public void setFileComponents(List<RichInputFile> fileComponents) {
              this.fileComponents = fileComponents;
          public List<RichInputFile> getFileComponents() {
              return fileComponents;
      The problems that I am facing are:

      1. I have clicked on the Add button; a new file upload component added to the page; I browse a file; Again clicked on the Add button; Another file upload component added and the first file upload get submitted (but it is having a border, or something similar); I browse file from the second file upload; Again click on Add button; now the first file upload get cleared (reset) and the second file upload get submitted;
      2. Whenever I clicked on the Add button the file get uploaded. Why? How to resist it? I have tried by setting atoSubmit="false" but no luck. Also tried to put the iterator, file uploader and the Upload button inside af:subForm
      3. My requirement is to Upload the file when the upload button is clicked, not before.

      Am I doing something wrong? Any pointer would be very helpful.