I am using the open method from Page to open a new window like this :
UI.getCurrent().getPage().open(url, “_blank”); (url being a String of course)
The issue I have is that the other line of code below are all executed before the window is displayed and I would like to wait for the window to open to continue my treatment afterwards.
you can’t stop the execution directly after that line, since then the response would never be sent to the browser. And since the window is opened as a result of that response, your code would essentially be in a deadlock at that point.
What you could do is add something to the UI of your window which does a callback when it’s actually opened - then in this callback method you could continue your execution while knowing for some certainty that the window is open (the user is still free close the window right after it was opened).
If you’re showing a vaadin UI in that window, the easiest way would be to just use a specific UI class for the window content and continue the execution in that UI’s init method, which is called when the UI is about to be sent to the browser (and the window would ofcourse be open).
May I ask what is the use case for this or what are you trying to do in detail? It might help us giving more reasonable answers.
We already have a Java desktop application from which you can consult a document. You can also consult the document from a link sent in an email. When you consult the document by accessing the link from the email or the application the database is updated to show that the document has been read.
So when you are doing an approval on that document, you need to have read it before approving or refusing it. When the user goes to read it, it is opened in a window. But since the execution continues, I reload the database value telling if its read or not and the window hasn’t appeared so of course the value is as if the user had not seen the document. (And then the user will be asked if he wants to read the document that he has already read…) The page that is opened is an asp page that will modify the database and load the file.
ok, I see - this case is a bit challenging to convert from desktop to any servlet environment (including vaadin). Basically I see a few options:
Redesign the whole logic to better cope with servlet application request-response lifecycle
Do not open the document directly, but create a separate Vaadin UI with just a BrowserFrame in it, and show the target page in that BrowserFrame. Then you could have a callback from that UI (or an extension of it) and finish the execution there.
Modify the ASP page to notify the vaadin application through some means that the window has actually been opened
If time/budget is a constraint, I’d probably go for option 2. Otherwise for option 1.