2

I have some code which extends a button to offer a download with FileDownloader:

private final InputStream stream;
private final Label label;
private final Button button;

//…

StreamResource.StreamSource source = new StreamResource.StreamSource() {
    @Override
    public InputStream getStream() {
        label.setValue("downloaded");
        return stream;
    }
};
FileDownloader downloader = new FileDownloader(new StreamResource(source));
downloader.extend(button);

This code wants to update the UI as well (set the Label to "downloaded"). This works in some browsers (Konqueror and Chromium), but in Firefox (31) it doesn't.

The behaviour in FF is quiet strange: The first click on the button starts the download without any update of the UI. A second click on the button shows the update of the UI only (i.e. no download).

My suspicion is that FF doesn't like FileDownloader's iframe:

Please note that the download will be started in an iframe

Any idea how I can achieve an update of the UI from within StreamSource.getStream()? If not, any better ideas to offer a download which updates the UI as well?

It's vaadin-7.1.15.

2 Answers2

0

maybe it will work when you update the label value in a clicklistener?

button.addClickListener(new ClickListener() {

    @Override
    public void buttonClick(ClickEvent event) {
        label.setValue("downloaded");
    }
});

I would also try to set the label to immediate=true:

label.setImmediate(true);
d2k2
  • 726
  • 8
  • 16
  • Using a ClickListener is my current workaround (i.e. yes it works). But I'm looking for a way to trigger the UI update from the FileDownloader, as I need to present information which is available after the initiation of that download. – user3895557 Aug 01 '14 at 06:29
0

You can either add the ClickListener to the button as suggested, or you need to let your UI poll the server (or even better use push). That the second click on the button will update the UI is caused by the fact, that this click initiates a client request and the server will answer with the changes in the UI. Before that you have updated the UI correctly - on server side - but the browser does not know about this. Therefore you should use UI listeners like the ButtonClickListener.

By the way I don't think that this is only a firefox issue.

riddy
  • 501
  • 1
  • 4
  • 17
  • Thank you. Could you elaborate how to push the updated UI-component? BTW I don't have that behaviour with Konqueror (webkit) or Chrome. – user3895557 Aug 07 '14 at 09:32
  • sure, thats quite easy, just say "setPollInterval(1000);" within your application (e.g. in the UI's init method) to verify if I'm right. There is no need to push some component or anything like that, this is just how Vaadin works. For every client request the server will respond with the diff UIDL to update the UI. Polling will just lead to client-requests without a user interaction (like your 2. button click) – riddy Aug 08 '14 at 12:02
  • one more hint I can give you is, that firefox will start downloads in the background without waiting for the user to click on the button. Maybe this has sth to do with your issue, that you cannot download twice? – riddy Aug 08 '14 at 12:47