Skip to content
Advertisement

Vaadin: Cannot get progress dialog to receive/react when the task completes

I’ve written a small Spring Boot/Vaadin application that displays a simple UI to take user input and make a call to another service that takes some time to run. When the task is submitted, I’m displaying a progress dialog that shows a progress bar, a message informing the user what is going on and a close button to allow them to close the dialog when the job completes. I’m using a ListenableFuture to be notified when the task is done.

I can get the dialog to appear with status of “executing” and the progress bar doing its thing, but when the task is done (I have debug statements going to the console to let me know), it’s not triggering the logic to update the status message and enable the close button. I can’t figure out what I’m doing wrong.

Here’s the code:

MainView1.java

JavaScript

ProgressDialog.java

JavaScript

BackendService.java

JavaScript

Note: I do have @EnableAsync specified in a @Configuration annotated class.

Advertisement

Answer

When dealing with asynchronous code in Vaadin you need to:

  • Use UI#access when updating the UI outside an active request. This acquires a lock on the UI, to prevent it being updated by two threads simultaneously.
  • Enable server push by adding the @Push annotation to your main layout or view. This allows the server to push updates to the client even if no request is active.

Without the former, you can get ConcurrentModificationExceptions in the best case, and very subtle bugs in the worst.

Without the latter, the changes will be applied (i.e. dialog closed), but the changes will only be sent to the client the next time the client sends a request. I believe this is your main issue.

More information can be found in the documentation.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement