File upload doesn't work with PrimeFaces 4.0,

2019-08-13 09:01发布

问题:

I have a web application running on:

  • Wildfly Beta 1
  • JSF Mojarra 2.2.3 (from Wildfly)
  • Primefaces 4.0
  • rewrite-servlet-2.0.7.Final / rewrite-config-prettyfaces-2.0.7.Final
  • commons-io-2.4 / commons-fileupload-1.3

And I have problem with file upload component (advanced and simple mode doesn't work, never print inside upload()).

Same is even run without rewrite-servlet-2.0.7.Final/rewrite-config-prettyfaces-2.0.7.Final libs.

My upload.xhtml file:

<h:form prependId="false" id="formLateralUpload" enctype="multipart/form-data">
    <h:panelGrid columns="1" cellpadding="5">
        <p:fileUpload mode="advanced" multiple="true" update="@widgetVar(msg)"
            fileUploadListener="#{test.upload}" auto="true" sizeLimit="10500000"/>
    </h:panelGrid>
</h:form>

My bean:

@ManagedBean(name = "test")
@ViewScoped
public class Test {
    private UploadedFile      file;

    public UploadedFile getFile() {
        return file;
    }

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

    public void upload(FileUploadEvent event) {
        System.out.println("inside upload()");
    }
}

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="test"
    version="3.1">
    <display-name>test</display-name>
    <welcome-file-list>
        <welcome-file>/</welcome-file>
    </welcome-file-list>

     <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>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

    <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>/faces/*</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
        <param-value>true</param-value>
    </context-param>

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/redirect</location>
    </error-page>
</web-app>

回答1:

I have the same issue with Wildfly 8.1, PrimeFaces 5.1, Pretty faces and file upload. There is a HACK to make this work in Tomcat, but I can't find one in undertow. PrettyFaces appears to be doing something bad to multipart post requests that prevents them from working correctly... They seem to be pushing it back to Undertow/Wildfly because the hack exists in Tomcat instead of fixing the actual issue.

Wildfly Discussion: http://ocpsoft.org/support/topic/pretty-primefaces-fileupload/

Tomcat Hack: http://ocpsoft.org/support/topic/split-prettyfaces-anchor-with-primefaces-file-upload-not-working/

I'm road blocked on this and I can't really extract either PrettyFaces, PrimeFaces-Fileupload (I need background ajax/html5 uploading) or Wildfly... Anyone with a suggestion other than "use an iframe/simple mode" would be much appreciated.