Combine closing a window with FileDownloader

The behaviour I am trying to create is that a user clicks a button in a Window and this will close the Window and start the file download using the FileDownloader extension.

I have tried various approaches with this, none of which have worked. Either the Window closes first so the file never starts to download or the file download is initiated correctly but the window does not close until something else triggers a repaint.

I’m sure I can’t be the first person to try and combine these two behaviours.

Could anyone suggest an approach that might make this work?

Hi James,

tried it with vaadin 7.3 and it works very well.

Code within the Component that extends Window:
Button btnDownload = new Button(“Download it!”);
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileDownloader fd = new FileDownloader(new FileResource(new File(basepath + “/test.pdf”)));

btnDownload.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
didnt try other Versions


i jave to correct myself…

its working as expected in chrome and safari, but it ist not working in firefox
as a workaround you could use this within the clicklistener:

FileResource res = new FileResource(new File(basepath + "/test.pdf"));
Page.getCurrent().open(res, "_blank", true);

unfortunately this method call ist marked as depricated, but it works.

Thanks for your help.

I had tried a solution similar to your first suggestion but I was using firefox. I assumed it was my code that was at fault and not something browser specific.

I am assuming that this is a bug that this does not work in Firefox then?

I don’t think you second solution is going to be viable for me as it gets blocked by pop-up blockers.

I have found a solution to my problem that seems to work.

I found that when debugging the file download would be initiated in firefox whilst the execution of the clicklistener was stopped at a break point.

Adding in a small sleep into the click listener of just a few milliseconds was enough to get the file downloading in Firefox.

I don’t know what factors influence how long the code would need to wait before closing the window though.