Advanced fileUpload get the file null with Primefaces [duplicate]

361
July 31, 2017, at 9:27 PM

This question already has an answer here:

  • How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable 7 answers

Environment:

  • Primefaces 6.1
  • JavaEE 7
  • Wildfly 10
  • JSF 2.2

when I click the button after having selected the file, the file var is null.

Test.xhtml

<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
        <h:head>
            <title>Application</title>
        </h:head>
        <h:body>
            <h:form id="frmTest" enctype="multipart/form-data">
                <ui:include src="template/messages.xhtml" />
                <p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false"
       update="messages" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
            </h:form>
        </h:body>
    </f:view>
</html>

TestBean.java

@ViewScoped
@ManagedBean
public class TestBean implements Serializable {
...
public void handleFileUpload(FileUploadEvent event) {
        UploadedFile file = event.getFile();//file is null
        FacesUtils.addInfoMessage("Succesful" + file.getFileName() + " is uploaded.");
        System.out.println("Succesful" + event.getFile().getFileName() + " is uploaded.");
}
...
Answer 1

You should remove or fill the update="" attribute from your fileUpload component. It "redirects" the files to a component after upload.

Rent Charter Buses Company
READ ALSO
I need help reading data from all files in a directory

I need help reading data from all files in a directory

I have a piece of code that iterates over all the files in a directoryBut I am stuck now at reading the content of the file into a String object

244
Software Architecture client Web / server

Software Architecture client Web / server

I’m a developer within a small software editor and I need some feedback on an architecture

287
Issue while evicting key from a cache using EvictProcesser

Issue while evicting key from a cache using EvictProcesser

I am trying to evict cache key using EvictProcessor, Does anybody know what this error means? I am getting this error with Coherence 37 while this code was working with Coherence 3

309
How to get currently ongoing call duration after user ends a call in android?

How to get currently ongoing call duration after user ends a call in android?

I am calling from my appAfter ends that call, I am trying to get a call duration

330