Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Updating UI component after buttonClick not working as expected
Hi,
I have a problem with a Button Clicklistener that is driving me crazy and I can't figure out how to do it right.
I hope you folks can help me out. We are using Vaadin 6.7.3.
Our application uses the BorderLayout add on and after click on a button a long running computation is done. To keep the user informed about what is going on a text in a status bar which is placed at the bottom of the window (BorderLayout.SOUTH) should be displayed BEFORE the long running task begins and the standard Vaadin loading indicator is shown.
The code for the onClick listener is pretty straight forward and looks like this:
final Button updateDataButton = new Button("Update Data");
updateDataButton.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
updateStatusBar("Updating data ...");
Dispatcher.dispatch(NavigationEvents.UPDATE_DATA);
}
});
updateDataButton.setImmediate(true);
addComponent(updateDataButton, 2, 15, 3, 15);
The method updateStatusBar changes the text of the label with the status information in the status bar. A call to Dispatcher.dispatch starts the long running task. The problem is, that the long running task starts and the Vaadin loading indicator is shown and AFTER the task has finished, the statusbar text is changed. The dispatch method doesn't start any threads or parallel tasks. We don't use a progress indicator and we don't want to use is. Please don't ask why :-) What am I doing wrong?
According to the code above the label in the status bar should be updated BEFORE the task and the loading indicator is shown?
I tried a few simple variations to see if it is general problem. For example, I changed the caption of the Button updateDataButton BEFORE a call to dispatch and the caption also changed AFTER the long running task finished.
The long running task runs approx. 30 seconds. But the problem is independent of the time. Even if the task runs for 1 seconds the problem is still there.
So I am pretty sure I am doing something wrong but I can't figure out what. I greatly appreciate any help on this.
Thanks in advance.
Peter
So you are not using threads, but instead operating a long running task that effectively blocks the UI thread?
When you call a method that sets a value of a Label or does anything, which needs a repaint (sending changes to browser), it doesn't mean that the change is immediately sent to browser and your code continues executing after the method call. Instead Vaadin engine collects all the changes and then sends the changes in an http response. Now when your long running task is blocking the UI thread in the event listener, the response containing the changes is also waiting for the task to complete.
If you really want to use synchronous call and don't want to use ProgressIndicator, you somehow need the client side to generate an event after you've updated the status bar and in that event listener you start the long running operation.