PrimeFaces p: fileUpload multiple files autoComplete only works after the first file

advertisements

I try to upload some files then redirect to another page by oncomplete the problem is that oncomplete is only working just after the first file is uploaded

<p:fileUpload  mode="advanced"
     label="#{FileMessages.file_add_file_lbl_Select_File}"
     fileUploadListener="#{fileAddFileAction.upload}"
     oncomplete="redirect(#{fileAddFileAction.groupId});"
     multiple="true"
     allowTypes="/(\.|\/)(txt|doc|docx|pdf)$/"
     widgetVar="fileUplaod" >
 </p:fileUpload>

Java Script function: redirect(groupId)

function redirect(groupId) {
     var url = "/network/group/files.html?gId="+groupId;
     $(location).attr('href',url);
}

bean.java

public void upload(FileUploadEvent event) {

    UploadedFile uploadedFile = event.getFile();

    try {
        String thumbnail = getDestination() + uploadedFile.getFileName();
        String[] filetype = thumbnail.split("\\.");
        String newfilename = Calendar.getInstance().getTimeInMillis() + "." + filetype[1];

        SystemFile file = new SystemFile();
        file.setAccount(getActor().getAccount());
        file.setCtime(new Date());
        file.setName(newfilename);
        file.setPath(getDestination());
        file.setFileType(FileUtil.checkFileType(filetype[1]));
        file.setOriginalName(uploadedFile.getFileName());

        getFileService().saveSystemFile(file);

        copyFile(getDestination() + newfilename, uploadedFile.getInputstream());

        copyFile(getDestination() + newfilename, uploadedFile.getInputstream());

    } catch (IOException ex) {
        Logger.getLogger(FileAddFileAction.class.getName()).log(Level.SEVERE, null, ex);
    }
}


It seems like a known issue : http://code.google.com/p/primefaces/issues/detail?id=3836

A custom patch has been done by a user on this page :

It can be used by adding the following line inside a p:fileUpload tag:

<p:ajax event="fileUploadsComplete" listener="#{filesBean.done}"/>

where the filesBean.done methode looks like this:

public void done(FileUploadsCompleteEvent event) {
    System.out.println("done");
}