I have a question related to the one that Michal Lichvar posted 2 years ago

I have a question related to the one that Michal Lichvar posted 2 years ago:
I want to provide a dynamic filename for the ResourceStream, i.e. the name of the resource being downloaded needs to depend on the name of a widget (in my case a tree-node) that was selected before the user clicks the Download button.

You suggestion back then was:
“…
Create a new StreamResource with the new name and use fileDownloadWrapper.setResource(streamResourceWithNewName);”

BUT: the code to create that new StreamSource and assign it would need to be executed after the user clicks the button. Otherwise I would need to create and assign such a StreamResource each and every time the user selected a widget just to be prepared for the (very rare) case that the user might click the download button after selecting that object.

One thus needs a piece of code that gets called and executed after the user clicked the button to create and assign the new StreamResource to the FileDownloadWrapper.

Is there any call-back that I could override? Or can I one add a click-listener to the button-wrapper? Or how can provide one provide a click-target dependent StreamResource to the FileDownloadWrapper?

Hope I could make myself clear…

Try https://vaadin.com/directory/component/lazy-download-button instead?

Thanks for the pointer. I was able to implement the desired feature using it but its error handling is VERY lacking. It can not handle the case when the name or content can not be provided (it just throws an NPE) and there is also no feedback if/whether the download terminated or not, which makes it impossible to react to the end of the download (be it successful or aborted), e.g. to update the UI accordingly like re-enable the download button again, etc. IMHO its not really acceptable for productive use.

I think you’re better off trying to improve the lazy-download-button add-on, to make it match your needs, rather than trying to implement the functionality you need with FileDownloadWrapper, which is intentionally very minimalist.

That’s exactly what I already started to do. ;-)