I want to upload a file with use of PrimeFaces and a ManagedBean. I want use p:fileUpload with mode="simple".
XHTML Code:
    <p:fileUpload id="fileId" mode="simple" value="#{itemBean.upFile}"
        fileLimit="1" />
    <p:commandButton ajax="true" value="Upload File" update="messagess"
                     id="save-btn"
                     actionListener="#{itemBean.fileUpload(itemBean.upFile,itemBean.hiddenFileName)}"
                     process="@this" oncomplete="showImage()" />
ManagedBean:
public void fileUpload(UploadedFile uploadFile, String hiddenKey) {  
    String keyFileName = hiddenKey;
    boolean validFile = true;
    String expression = "([^\\s]+(\\.(?i)(gif|jpg|jpeg|gif|png|PNG|GIF|JPG|JPEG|bmp))$)";
    if((uploadFile == null) ) {
        validFile = false;
        FacesMessage msg = new FacesMessage("Error! "+ "Please select an image.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }  
    else {
    System.out.println("going to file upload"+uploadFile.getFileName()+"---hiddenKey"+keyFileName);
    if((!uploadFile.getFileName().matches(expression)) ) {
        validFile = false;
        FacesMessage msg = new FacesMessage("Error! "+ uploadFile.getFileName() + " is not an image.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    if(uploadFile.getSize() > 1000000) {
        validFile = false;
        FacesMessage msg = new FacesMessage("Error! "+ uploadFile.getFileName() + " size is too large.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    if (validFile) {
        // Do what you want with the file        
        try {
            //String extn =uploadFile.getFileName().substring(uploadFile.getFileName().lastIndexOf("."));
            copyFile(uploadFile.getFileName(), uploadFile.getInputstream());
            FacesMessage msg = new FacesMessage("Success! "+ uploadFile.getFileName() + " is uploaded.");  
            FacesContext.getCurrentInstance().addMessage(null, msg);
        } catch (IOException e) {
            e.printStackTrace();
            FacesMessage msg = new FacesMessage("Error! "+ uploadFile.getFileName()+ " not uploaded.");  
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }
    }
}  
My problem is, that I clicked on the command button and method in the backing bean is not called.
If I use ajax="false" the method is called, but the page got refreshed.
How can I use ajax="true" and <p:fileUpload> together?
 
     
    