Lazy Loading View

Hi,

I’m new to vaadin and I’m stuck with something:

I’ve got a menu ( 3 buttons ), every button opens some other view. The view contains some data from my REST API so it takes some time to load it, so I wanted to show up a progress bar when the view is loading ( besides having the loading indicator at the top ).
So I’ve tried :

ProgressBar pB = new ProgressBar(); pB.setIndeterminate(true); addComponent(pB); navigator.navigateTo(myView); But the progress bar was not shown and the new view was loading ( with the loading indicator at the top )

Tried setting up a Future in the new View :

Future<Rack> future = null;
try {
future = storageDTO.downloadRack();
} catch (Exception e) {
 e.printStackTrace();
 }
showProgressbar();
while (!future.isDone()){
 checkIfDone(future);
} 

private void checkIfDone(Future<Rack> future) {
if (future.isDone()) {
hideProgressbar();
Rack rack = null;
try {
rack = future.get();
...rest of the logic

And it loads properly, but the view waits for the future to be done so it can display my rack component.

I want it to show up the view, show the progress bar after the loading is done, when the loading is done hide the progress bar and display the rack component.
How can I achieve this?

Thanks for the help

Hi,

If I understoot correctly, you would like to open a view and show a progress bar while data is being fetched in the background. And when the data is avaialble, hide the progress bar and show the content of the view?

One thing that would be worth checking out is the
Server Push
documentation. Basically, what you would do is to query for the data from a background thread, then when the data is avaialble, update the UI by hiding the progress bar and displaying any additional components.
Just remember that when updating the UI from a background thread you have to use the ui access() method.

Hope this helps,
Goran