p:fileUpload does not set any value

34 views Asked by At

I'm trying to upload a file from the jsf view to be used in Java code, and for that i'm using p:fileUpload as follows:

The view:

<h:form id="exportForm" class="formClass"
    enctype="multipart/form-data" rendered="true"
    style="margin: 100px 50px;">
<p:fileUpload value="#{bean.importFile}" mode="simple"
    allowTypes=".xls"
    invalidFileMessage="#{msg['bean.InvalidMessage']}"
    sizeLimit="500000"
    invalidSizeMessage="#{msg['bean.maxSizeMessage']}" />
<h:commandButton
    value="#{msg['bean.uploadFileMsg']}" ajax="false"
    actionListener="#{bean.uploadFile}" styleClass="btn btn-primary">
</h:commandButton>
</h:form>

In Java, the file has its setter and getter

private UploadedFile importFile;

public UploadedFile getImportFile() {
    return importFile;
}

public void setImportFile(UploadedFile importFile) {
    this.importFile = importFile;
}

web.xml

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

But every time I try to upload a file, its always null:

public void uploadFile() {  

        if(importFile != null) {  //null
           .
           .
           . 
        }
}

Also, the Java class implements Serializable is marked as:

@ManagedBean(name = "bean")
@ViewScoped

I'm using:

  • commons-fileupload 1.3.3
  • commons-io 2.5
  • JSF 2.0
  • Primefaces 7.0

I can't see what i'm missing.

0

There are 0 answers