Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Is there a "client UI ready" event?
I need to perform some asynchronous work on the server-side as soon as the client UI is being displayed. However, I cannot start it when the UI Java Object is constructed, as this would be too early, and any fixed delay is just hacky and unreliable. Is there something like "document.ready()" for a Vaadin UI that I can react upon at the server side? I would like to start my background job as soon as the client sees the UI on-screen for the first time (i.e. the loading indicator when opening a UI has disappeared on the client side).
I'd be grateful for any advice.
I don't think there's anything built-in to accomplish this. I think you could implement this with a simple UI extension which would do an RPC call to the server. The RPC call should be handled only after the rendering loop on the client has finished, so once the request comes to the server you'll know that the rendering has finished.
How do you add code "after the rendering loop on the client has finished"?
Seems like a core feature that Vaadin ought to provide, though I've never had an issue with the UI not being ready yet. It has been trouble for custom JS widgets, though, in which they may take longer to be ready, and we did just what you suggest, which is send a message once the JS widget's code is considered complete.
So, to clarify what I need it for: among other things, I have a table component on the initial view of my web application. This table needs to be filled with data from a query. This is done asynchronously using a worker thread on the server, and the values are pushed to the client via server push (in the meantime, a loading indicator is shown instead of the table).
The problem is: if I start the worker thread when the UI object is created on the server, then the query sometimes finishes too early. The server sends the push update to the client, which is still busy building up the UI. In the end, the push update is lost and the application freezes on the client side as it is no longer in synch with the server.
The obvious solution would be: wait until the client has rendered its UI before starting the query evaluation worker thread on the server. Vaadin does not provide this functionality out of the box.
I like the solution suggested by Teppo, however: which event should the GWT extension component react upon? To my current knowledge, it should be GWT "Widget#onLoad()", as this is called after rendering is done. Unfortunately, this is a protected method and only available to subclasses of "Widget". If I write a Vaadin Extension, there is no Widget (only a connector).
I have the same problem. Have you found any solution?