FileUpload - Simple

Simple uploader uses native browser file upload.



Source

<h:form enctype="multipart/form-data">

    <p:messages showDetail="true"/>

    <p:fileUpload value="#{fileUploadController.file}" />

    <p:commandButton value="Submit" ajax="false"
                actionListener="#{fileUploadController.upload}"/>

</h:form>
                    
package org.primefaces.examples.view;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.model.UploadedFile;

public class FileUploadController {

    private UploadedFile file;

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }

    public void upload() {
        FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
		FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}