File Chooser for downloading multiple files

Hi,

Is there any component in Vaadin 7 using which we can display file chooser to download selected multiple files?

Hi,
You might have a look at the MultiFileUpload add-on

Thanks Koenraad for your reply. But that add-on in not applicable for me as it is used for uploading files. I want the functionality for downloading multiple files.

Hi Rasika,
Indeed, I got it wrong.

For multiple file download, I don’t know whether a filechooser solution is available. I have tried using the standard FileDownloader in combination with Grid. In fact, I am extending several FileDownloaders to one button.
After selecting files and clicking on the multidownload button, all are downloaded simultaneously in the default download folder.

It’s not working perfect yet…

//... define layout with components

multiDownload = new Button("Multiple Download");
multiDownload.addClickListener(new ClickListener() {
    @Override
    public void buttonClick(ClickEvent event) {
        //after clicking and downloading, remove the FileDownloaders linked to the button
        //todo : wait for end of download before removing extensions
        Iterator<Extension> extensionIterator = multiDownload.getExtensions().iterator();
        while (extensionIterator.hasNext()) {
             multiDownload.removeExtension(extensionIterator.next());
        }
        multiDownload.setEnabled(false);
   }
});
addComponent(multiDownload);

//... define Grid and add a column containing a button to select the files to be downloaded
grid.addColumn("FileName", String.class);
//...
grid.addColumn("Button", String.class);
grid.getColumn("Button").setRenderer(
     new ButtonRenderer(e -> selectPressed(grid.getContainerDataSource().getItem(e.getItemId()))));
////...

... fill the Grid with files
grid.addRow(fileName,.... , "select");

.. the rest of your UI


private void selectPressed(Item selectedItem) {
    String fileName = (String) selectedItem.getItemProperty("FileName").getValue();
    //my files are located in the temp folder
    FileResource fileResource = new FileResource(new File(System.getProperty("java.io.tmpdir")
         + "demo//" + fileName));
    FileDownloader fileDownloader = new FileDownloader(fileResource);
    fileDownloader.extend(multiDownload)
    multiDownload.setEnabled(true);
}

Hi Koenraad,

Its working!! Thanks a lot!! :slight_smile:

Hi Koenraad,

I am facing issues while running it in internet explorer. The IE version I am using is 9.

Also, I am not able to extend the same component once I have removed it.

Hi Rasika,

I didn’t test with IE, but maybe your problems are linked with this post :
https://vaadin.com/forum#!/thread/8675979

Hi Koenraad,

I am facing the same task, but I cannot make it work so far.

In contrast to your proposal I thought it might be clever to extend the Button after the click of the user, than click again (exportButton.click) to download the files and remove afterwards the extensions.

[code]
@Override
public void buttonClick(ClickEvent event) {
if (!this.isButtonStateDownload) {
this.isButtonStateDownload = true;
// extend Button and click again
this.overviewView.exportFiles();

        while (event.getButton().getExtensions().iterator().hasNext()) {
            Extension myExtension = event.getButton().getExtensions().iterator().next();
            event.getButton().removeExtension(myExtension);
        }

        this.isButtonStateDownload = false;
    }
}

[/code]My Problem is, that removing the extensions lead by your proposal to a ConcurrentModificationException. With the code above it runs, but it does not export the files anymore (probably, because the FileDownloader is not yet ready?). It works fine when not trying to remove the extensions, but I do not think, that this is a good solution.

The reason why not extending in advance is, that I use checkboxes to select which files should me exported, but I use them also with a delete button and it might be quite annoying if a click takes to long although the user only wants to delete these files but not download them.

Any suggestions how to deal with that?

Thank you
Regards

Patric