How to create a waiting window/dialog in v14

On v7, I have a Window that popup with some “wait a moment…” or “retrieving data…”, while this Window block the app, it may be updating all kind of components behind (mostly Grids)

The flow is like this:
Create a Dialog, adding a task (a thread) that will start with the dialog is attached, when the thread finish (in any way, interrupted/canceled by user, etc) the dialog is closed.
This task normally is retrieving data from a backend and updating view, populating grids, while the Dialog is blocking any user input.

I found that in v14 I have to use Dialog, added a progressBar, a label/span for status info, but after Dialog#open(), nothing is updated, nor the grid behind, the text to be appended in the statusLabel.
I find out that I have to retain an instance of UI at the constructor of the Dialog, because in the any other moment UI.getCurrent() returns null so I can’t do this inside the Dialog class for example:

`
public class WaitingWindow extends Dialog {

public void setStatusLabel(String news) {
//this doesn't throw exception, but doesn't update the label neither
	ui.access( () -> statusLabel.setText(news));
	//when the dialog is about to close, a few milliseconds before the label is updated
}

`

In the “task”, a thread that starts running when the dialog is attached, in the controller side the Grid isn’t upgrade and throws

java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
   at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:527)
   at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:541)

How did u implement this? is it any Vaadin build-in component that I am not aware of?, instead of wasting lot of time trying to handle session blockings, threads etc etc

I found this [thread]
(https://vaadin.com/forum/thread/15304760/vaadin-8-ui-getcurrent-returns-null-on-non-request-threads) where it is explained why all is broken (or “work as designed”) at last and I am getting UI nulls, but still no clue why components are not updated

do you have the [@Push]
(https://vaadin.com/docs/v14/flow/advanced/tutorial-push-configuration.html#push.configuration.annotation) annotation on your view or routerlayout? Or maybe you have the push mode set to manual, so you’d need to manually call ui.push(); in the end of an ui.access() block.

See [Asynchronous Updates]
(https://vaadin.com/docs/v14/flow/advanced/tutorial-push-access.html), and also [a recent SO answer of mine]
(https://stackoverflow.com/a/62424887/3441504) for an example how to avoid getting only null instead of a UI.

thanks, I shrunk a piece of code (for simplification purpose, but I guess it was useful hehe) that I didn’t put in my post to check Push status

public void setStatusLabel(String news) {
//this doesn't throw exception, but doesn't update the label neither
	ui.access( () -> statusLabel.setText(news));
	doPush(forcePush); //
}

private void doPush(boolean forcePush) {
        if (!ui.getPushConfiguration().getPushMode().equals(PushMode.AUTOMATIC) || forcePush) {
            ui.push();
	}
}

I can’t annotate my WaitingDialog because

  Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: com.vaadin.flow.server.InvalidApplicationConfigurationException: Found configuration annotations that will not be used in the application. 
Move it to a single route/a top router layout/web component of the application. 
Class 'com.gmail.joseluis.WaitingWindow' contains 'Push', but it is not a router layout/top level route/web component

I guess I will have to play more around with v14 and forget a lot of v7 to make this work and all this “new design” of passing UI instance.
I am not sure about the pros/cons of having the whole proyect with @push auto or manu

If you don’t know the difference between manual and automatic push, then just use automatic. You can then remove your doPush method (which would have to be called within the ui.access(..) block).

And about the annotation error: you need to annotate the view (where also the @Route annotation is), or in the used RouterLayout of that view. It will then automatically work inside your waitingWindow too if it is opened inside that view.

I didn’t mean about auto or manual, I was thinking about push in general, having any push mode “active”, is it generate more traffic between server and clients? has a performance impact (for who)?, why isn’t active and automatic by default?
I can’t imagine any scenario where u don’t need to use this feature

PD: The doPush(boolean) method is made in that way because is part of my “VaadinUtilities” project, and the Main projects may or not has enabled, it also has another consideration for UI.getCurrent().setPollInterval(pollInterval); (usuarlly 500mill) for when there is no push. All these configuration works great in my V7 projects in the last 5 years.

Thanks for you time and help!