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?