A couple of weeks ago I found this interesting question in the forum:
I figured it was a perfect chance to try some live coding and record a video explaining how to implement a simple application with these requirements:
1. Allow users to upload a file.
2. Show a spinner in the UI while the file is being uploaded.
3. When the file is uploaded, process the file in a background thread in the server.
4. Show the progress of the processing task in the UI.
Here’s the video showing how to implement the app from scratch using Spring Boot and Vaadin Framework 8 (code available on GitHub):
The main takeaway is to enable push and use the UI.access(Runnable)
method when making changes to the UI from a new thread. For example:
@Push // enable UI updates from background threads public class VaadinUI extends UI { ... private void someMethod() { ... new Thread(() -> { ... access(() -> { // UI modification code here }); ... }).start(); } }
Stay tuned and see you next week with another community inspired answer!