java - ADF Faces 多个文件上传

标签 java file-upload oracle-adf

我正在尝试使用多个 af:inputFile 组件创建多个文件上传。这是我的 xhtml:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1" title="Home">
      <af:form id="f1" usesUpload="true">
        <af:commandButton text="Add" immediate="true"
                          actionListener="#{viewScope.massUpload.add}"
                          id="cb2"/>
        <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"
                          value="#{viewScope.massUpload.files[status.index]}"/>
          </af:iterator>
          <af:commandButton text="Upload"
                            actionListener="#{viewScope.massUpload.upload}"
                            id="cb1"/>
        </af:panelGroupLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

这是托管 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() {
        super();        
    }

    public void add(ActionEvent event) {   
        fileComponents.add(new RichInputFile());
        files.add(null);
    }

    public void upload(ActionEvent event) throws IdcClientException {
        for(UploadedFile file : files) {
            System.out.println(file.getFilename());
        }
    }

    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;
    }
}

我面临的问题是:

  1. 我点击了“添加”按钮;页面添加新的文件上传组件;我浏览一个文件;再次点击添加按钮;添加了另一个文件上传组件,并提交了第一个文件上传(但它有边框或类似的东西);我从第二个文件上传浏览文件;再次点击添加按钮;现在第一个文件上传被清除(重置),第二个文件上传被提交;
  2. 每当我单击“添加”按钮时,文件就会上传。为什么?如何抵抗呢?我尝试过设置 atoSubmit="false"但没有运气。还尝试将迭代器、文件 uploader 和上传按钮放入 af:subForm
  3. 我的要求是在点击上传按钮时上传文件,而不是之前。

我做错了什么吗?任何指针都会非常有帮助。

最佳答案

我看到您正在使用 IdcClientException,它告诉我您正在上传到 UCM。如果您也在使用 WebCenter,那么您也许可以使用 WebCenter Portal 附带的开箱即用的上传任务流:http://docs.oracle.com/cd/E29597_01/webcenter.1111/e25595/jpsdg_content_jsfpg.htm#autoId18

从 PS5 开始,任务流程将为您执行多文件上传。

关于java - ADF Faces 多个文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224425/

相关文章:

java - 我应该为 DTO 使用 Serialized 吗?为什么应该使用?

flutter - 如何在 Flutter 中将图像和文件上传到服务器?

c# - 机器人框架 : Detect when the user uploaded a file

php - Android 允许将多个文件上传(最大 150 MB)到 PHP 服务器

jakarta-ee - Oracle ADF 的灵活性如何?

java - 如何通过Android套接字获取输入的字符到java服务器

java - 如何让这个面板作为内部类工作?

java - 无法从与类相同的文件夹加载 xml

java - UIViewRoot 为空 ADF_FACE-30179

java - jdeveloper/adf 中的 .jws 、 .jpr 和 .jpx 文件是什么?