[7.5.1] FileDownloader - selected files download - first click is working


We’ve created solution where user has a table with files, each entry has checkbox. He can select as many as he like and then click download button.

We are using such resource, it should allow dynamically download, depending on selected items

 private StreamResource createResource(final IndexedContainer container) {
            return new StreamResource(new StreamSource() {
                public InputStream getStream() {
                    for (Object o : container.getItemIds()) {
                        CheckBox checkbox = (CheckBox) container.getItem(o).getItemProperty(C_CHECK_BOX).getValue();
                        if (checkbox.getValue()) {
                    // do some magic to get stream of selected files

            }, "download.zip");

The problem is that only second and following click on button is giving expected restults.

It’s turns out that FileDownoader is getting resource from server and then it is sending current status of component . It is the reason why first click is giving stale result.

Do you have any idea how to overcome this? Is it possible to force: first update component and then download the resource?

Many thanks

Not positive, but we saw something similiar and it seems that the connector ids or the like were being cached/reused and so browsers were sometimes showing a previous result. I don’t know if that’s what you are experiencing or not. I think there’s a cache setting on the DownloadStream or something that may default to 1 day.

I managed to resolve this. @David it was not the case, but thanks for this hint!

You can check solution at

Ah, didn’t even read it clearly as the cache issue is subsequent clicks get stale, not first! Of course a link to the thread would be more helpful than one just to stack overflow.