Within my application, what I have is a long-lasting process which processes some calculus in the server (best routes of some vehicles and so on). I want to show to the user a progress bar indicating the current status of the process.
In theory, everything seem easy. I have a ProgressBar object in my View. This progress bar will be updated via a Listener, which will be written as a normal Interface, say IProgressListener, which one method called notifyProgress(float pValue). When a new value is generated in the server (running the calculate()) notifyProgress() will be called. In my view, it will be defined an instance of IProgressListener overriding the notifyProggress(float pValue) method, which will do the progressBar.setValue(pValue); stuff.
Unfortunately, when running my webapp, the progress bar remains stuck, with no value update, until the long-taking process is finished. Here is when the progress bar goes ahead, repidly, to the end at 100%
Does anybody know why is this happening?
Thank you in advance.
EDIT:
Finally, I've been able to make it work. I've replaced the usage of IProgressListener and I've implemented the Observer Pattern. Strange as it may seem, I've not wrapped the UI updates between the ui.access( () -> { //code here }); snippet (otherwise, UI changes wouldn't work if introduced here).
There is a thread on vaadin forum worth reading which summarizes this well - Updating UI from another thread:
Vaadin consists of a server side that runs in a servlet container and a client side that runs in a web browser. The application state is kept on server side but communication is initiated by the client side whenever needed e.g. when a button is clicked.
Since HTTP is request-response, normally there is no way for server to send data to client at will unless the server is directly asked. There are two main techniques to overcome this:
Note that forum thread mentioned above mentions special vaadin add-on for using push, but since then regular server push based on Atmosphere Framework became part of the Vaadin Framework. While websockets are supported in all modern browsers, there can be problems with proxies or older browsers. The atmosphere frameowrk provides various alternative automatic fallbacks if websockets are not available.