I am facing a problem with <p:fileUpload>
of PrimeFaces. I created a Facelet page to upload a file as below:
<h:form id="welcomeForm">
<p:fileUpload value="#{fileUploadController.uploadedFile}" mode="simple" />
<h:commandButton value="Submit" action="#{fileUploadController.submit}" />
<h:message for="welcomeForm" />
</h:form>
And a backing bean as below:
public class FileUploadController {
private UploadedFile uploadedFile;
public FileUploadController() {
}
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
public void submit() {
// Get information you from the uploaded file
System.out.println("Uploaded file name : " + uploadedFile);
}
}
When I click the Submit
button, the method submit()
is called but it the result is as below :
INFO: Uploaded file name : null
How is this caused and how can I solve it?