Primefaces 多文件选择在 IE11 浏览器中不起作用

Primefaces multi file selection not working in IE11 browser

我正在尝试在 IE11 浏览器中使用 primefaces5.2 实现多文件上传,但它不允许我一次 select 多个文件。

同样的东西在 chrome 浏览器中运行完美。

配置的罐子:

javax.faces.jar(JSF2.1.9),Primefaces5.2.jar ,Weblogic 12c

Web.xml :

<web-app>
  <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
     <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>
<context-param>
    <param-name>primefaces.UPLOADER</param-name>
    <param-value>auto</param-value>
</context-param>
 <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class> org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
 </filter>
 <filter-mapping>
   <filter-name>PrimeFaces FileUpload Filter</filter-name>
   <servlet-name>Faces Servlet</servlet-name>
 </filter-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

fileUpload.xhtml :

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
 </h:head>
<h:body>
     <h:form enctype="multipart/form-data" >
            <p:fileUpload value="#{fileUploadBean.file}" mode="advanced" multiple="true"
                            fileUploadListener="#{fileUploadBean.fileUploadListener}"></p:fileUpload>
    </h:form>
  <h:body>
 </html>

FileUploadBean.java

 @ManagedBean
 @SessionScoped
 public class FileUploadBean {
    UploadedFile file;

    public UploadedFile getFile() {
    return file;
     }

    public void setFile(UploadedFile file) {
     this.file = file;
     }

   public void fileUploadListener(FileUploadEvent e){
    // Get uploaded file from the FileUploadEvent
    this.file = e.getFile();
    // Print out the information of the file
    System.out.println("Uploaded File Name Is :: "+file.getFileName()     +" ::    Uploaded File Size :: "+file.getSize());
    }

请删除值属性。在高级模式下,Primefaces 会为每个文件调用监听器,该值不是必需的。

  <p:fileUpload  mode="advanced" multiple="true" 
      fileUploadListener="#{fileUploadBean.fileUploadListener}">
  </p:fileUpload>

您应该使用列表而不是单个文件

ArrayList<UploadedFile> files = new ArrayList<UploadedFile>();

并在方法中将文件添加到列表

files.add(e.getFile());

此外,请确保 SessionScoped 是最适合您的范围。因为,大多数时候使用 ViewScoped 更好。

在 IE 11 中,我的 Web 应用程序处于兼容模式,我从兼容模式中删除了 Web 应用程序,现在我可以 select 多个文件。