How do I create a button to dynamically download a file with a progress bar and validation?

ASpecifically the creation of the file content can take some time, enough to warrant a progress bar. I also need to have some validation when the button is pressed to confirm everything on the screen is valid and if not to present some kind of notification.

I saw a couple of addons in the Vaadin directory but they both seem to be immediately start the download. I also tried to manually do it by registering the StreamResource and then opening it with JS but that runs into random issues with timing.

Any suggestions on how to do this would be greatly appreciated.

the simplest pattern would be a two staged creation:

  • Add Button “Create” which toggles the progress bar, creates the file and the does the checking
  • once the file is created a link “Download” is shown below

I’m really trying to avoid that because it doesn’t flow at all with the workflow or UI.

In most cases it’s only a few seconds.

That being said I also looked at a hidden anchor but I couldn’t see a nice way to click it. Maybe through JS but it started to get a bit convoluted…

I also looked at addons like FileDownloadWrapper and so on and make them invisible and click them those when ready but that didn’t seem to work either.

If I remember correctly you can’t click links, this always requires a user interaction because of security

Have you checked this example Grid CSV export with Download button in a Dialog. You need have Anchor attached to view in order to not detach it while Dialog is closed by Button click. · GitHub

Based on Directory discusssions, you finally implemented this with the DynamicFileDownloader in the Viritin add-on. We should probably create an example how to do it :thinking: In your case, how did you do it finally? More specifically, did you settle on “indeterminate progressbar”, were you able to notify/update the progress bar from the file generation or did you estimate the progress from another thread?