1

I am trying to download a zip file using Vaadin without the user having to click a button. This can be done using Page.open(). My problem is that I am setting the StreamResource to download this way:

    final StreamResource myResource = createResource();
    setResource("dl", myResource);
    getUI().getConnectorTracker().setDiffState(this, null);
    final ResourceReference ref = ResourceReference.create(myResource, UI.getCurrent(), "dl");

Unfortunately ref.getURL() is null, which does not allow me to open the file. This thread is the approach I was trying to implement.

Community
  • 1
  • 1
mgrstnr
  • 490
  • 1
  • 5
  • 23
  • I'm not sure this is intended to work in vaadin 7. A NULL URL is usually meaning that the component is not yet bound to the "output" dom tree. Perhaps it would be better to use request handlers?? https://vaadin.com/book/-/page/advanced.requesthandler.html – André Schild Jun 26 '14 at 09:13
  • Where are you using this code? Inside of a `Copmonent`? Why the `FileDownloader` and setDiffState(this, null)? Further you should create the `ResourceReference with the same Component us are setting the Resource. – raffael Jun 26 '14 at 10:04
  • @raffael Sorry about the 'FileDownloader' it was in there from a previous version. I am using it inside a Component. – mgrstnr Jun 26 '14 at 11:21
  • What version of vaadin are you using. In vaadin 7.2.2 (and probably all vaadin 7 version) I don't see how getURL() should return null. But the way you are creating a `ResourceReference`, it will return a false url. You should use the current `Component` object (most likly just "this") instead of UI.getCurrent(). – raffael Jun 26 '14 at 13:37

0 Answers0