getApplication().getMainWindow().open() vs getWindow().open()

Hi,

In my application the user clicks on a button to download a certain report that is generated with a servlet. In my code I had something like

to download the report.

However, recently this stopped working in the sense that on Mac and also using Chrome on Ubuntu (with Firefox it works fine) it downloads the report when you click the button, but after a second or so the UI suddenly displays the ‘red spinning wheel’ in the top-right corner. the only way to make it go away is to press the ‘refresh’ button of the browser.

I tried various things, and discovered that the problem went away when I use getWindow().open() instead of getApplication.getMainWindow().open().

I’m happy I solved my problem, but I would also like to know why I fixed it. Is there any reason why this change would solve the problem? It seems to be browser dependent, so maybe I was just lucky, but if anybody can give some information on why the behavior would be different, most welcome.

Maybe something that can shed some light on the root-cause: the download finishes fine (the complete file is downloaded), but the red-spinning wheel prevents any further UI operations.

Thanks,
Kim Marivoet

Hi,

Are you using multiple windows in your app? If there’s just one window, the getWindow() and getMainWindow() should point to the same Window object. But if you have multiple windows, calling getMainWindow() in a non-main window returns the wrong Window object.

In the case where I have the problem there is only 1 window. At the end it turned out that replacing getApplication().getMainWindow().open() with getwindow().open() didn’t solve my problem (which is kind of logical).

I managed to solve my problem with a dirty hack:

  • create a non-modal window that is a child of the main window
  • put this window somewhere outside of the screen, to make it invisible
  • let this window do all the ‘open(new ExternalResource(url))’ calls.

It’s dirty, but it seems to work (I don’t have the red spinning wheel anymore, and all content is downloaded).

What worries me a bit is that I don’t know the root-cause of the original problem. It’s also only in very specific cases: I have to deploy the Vaadin backend on a VMWare server, and have it return real results (the resource I’m trying to open is the result of opening a certain record in a database). When I stub the database code inside the servlet, or run the servlet locally on my desktop, connected to the real database, the problem doesn’t happen, although in both cases the correct result is downloaded and saved locally by the browser. Only on the VMWare server the red spinning wheel appears. It might be some subtle timing or something, but I can’t for example send you an isolated piece of source code that reproduces the issue.

Anyway, thanks for your answer.

regards,
Kim Marivoet