Jackson Bray
Jackson Bray

Reputation: 255

PrimeFaces uploadFile, trying to upload multiple files and stopping at one

So basically, I have a fileUploader that I want to do multiple files at a time. When I click upload with 2 or more files, it runs the event handler once, and then stops, not running it again for the rest of the files, even though it shows them in queue on the page.

        <h:panelGroup>                               
            <h:panelGrid columns="3" >
                <h:outputText value="Attach Files:"/>
                <p:fileUpload allowTypes="/(\.|\/)(doc|docx|xls|xlsx|pdf)$/" mode="advanced" multiple="true" sizeLimit="30000000" auto="true" fileUploadListener="#{requestPart.handleFileUpload}" update="messages"/>
                <p:messages id="mgs" showDetail="true"/> 
            </h:panelGrid>
        </h:panelGroup>

My event handler code is as follows

private List<UploadedFile> uploadedFileList = new ArrayList<UploadedFile>();

public void handleFileUpload(FileUploadEvent event) throws NotSupportedException, SystemException, SQLException
{

    System.out.println("Uploading Request Part files....");
    UploadedFile file = event.getFile();
    uploadedFileList.add(file);
    FacesMessage msg = new FacesMessage("File attached successfully.", file.getFileName() + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);  

}

Could anyone point me in the write direction? As far as I know, the event is just one file at a time and never a list?

Upvotes: 0

Views: 2432

Answers (2)

Jes&#250;s Rangel
Jes&#250;s Rangel

Reputation: 1

My solution is:

sequential="true" add in your fileUpload and your bean

 private List<UploadedFile> archImagen;

 public void handleFileUpload(FileUploadEvent event) {
        archImagen.add( event.getFile()); 
}

Upvotes: 0

cctt
cctt

Reputation: 11

Which version of PF? I had similar problem with PF 5.0. Try with this:

    public static synchronized void addToList{
    uploadedFileList.add(file);
    }

Upvotes: 1

Related Questions