There is a code page:

<h:form style="margin: 5%"> <p:growl id="messages" showDetail="true" /> <p:fileUpload value="#{mainBean.file}" mode="simple" allowTypes="/(\.|\/)(xml|docx)$/" skinSimple="true"/> <p:commandButton value="Submit" actionListener="#{mainBean.upload}" disabled="false" /> </h:form> 

The class code is as follows:

 private UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; } public void upload() { if(file != null) { FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded."); FacesContext.getCurrentInstance().addMessage(null, message); } } 

How everything works at this stage: the user clicks on the "+ Choose" button, a dialog box opens, the user selects the file, clicks "Ok". The page displays the file name. Next you need to click on the "Submit" button to upload the file to the server. How to implement it, tell me, please?

    1 answer 1

    You have "lost" two important properties from the example text on the website of the Primefaces .

    1. The enctype="multipart/form-data" property is enctype="multipart/form-data" for the h:form component h:form
    2. The ajax="false" property is missing for p:commandButton

    Due to the lack of the first, the file download format is violated, due to the lack of the second, the entire form does not submit . After adding properties, file loading works.