I would like to share a small issue I was having and was able to solve myself, but I couldn’t find the solution online and it took me some time to realize what the issue was. Hopefully if someone else has the same problem they may save some time.
This is using Vaadin 8. It is probably applicable to other versions as well
I had a page with a grid control which can be manipulated in many application-specific ways and a button aimed at downloading the content of said grid. I had implemented this with the guidance of this page [Letting The User Download A File]
(https://vaadin.com/docs/v8/framework/articles/LettingTheUserDownloadAFile.html) which specifically has a section on creating the content dynamically.
My code was something like this:
StreamSource downloadSource = () -> new ByteArrayInputStream(createDownloadFile());
StreamResource downloadResource = new StreamResource(downloadSource, "grid_data.csv");
FileDownloader downloadDownloader = new FileDownloader(downloadResource);
downloadDownloader.extend(content.downloadButton);
So, the page loaded, the user could work on the grid as much as they liked, and only when they hit the download button was the code to generate the file executed. The file was downloaded and all was ok… that one time. If later on the user continued to manipulate the data and hit the download button a second time, they got exactly the same file as the first time. The code to generate the file was not called again.
I had even tried to subclass InputStream in a way that it would return new content after it was read a first time and still after the first file was downloaded no more calls were even made to the stream’s read() method.
It turns out that since the target of the download button is not really changing, it is subject to caching. Setting the cache time to 0 is what finally solved the issue:
StreamSource downloadSource = () -> new ByteArrayInputStream(createDownloadFile());
StreamResource downloadResource = new StreamResource(downloadSource, "grid_data.csv");
downloadResource.setCacheTime(0);
FileDownloader downloadDownloader = new FileDownloader(downloadResource);
downloadDownloader.extend(content.downloadButton);
Anyway, it may seem quite silly, but I hadn’t found any reference to this and it drove me nuts for a bit. I hope this post saves someone from going through it too.