wait...

I’ve tried using Timer and also looked at https://vaadin.com/forum/thread/1520473/how-to-wait. they said I cannot wait, but all I want to do is show an image and then wait one second and redirect them. but I’m not able to do that simple task?

they also said to use the event to do these actions but I don’t see how I can use any event to do this? anyone knows?

current code:

            Dialog LOADED = new Dialog();
            LOADED.setCloseOnOutsideClick(false);
            LOADED.setCloseOnEsc(false);
            LOADED.add(new Image(imageLink, "Registered Guild!"));
            LOADED.open();
            //wait 1 second
            UI.getCurrent().navigate("/panel/server");
            ```

You can do that, but you need to enable @Push. The way Flow works is that events go to the server, the server figures out what the updated UI state is, and sends a response to the browser with instructions on how to update the DOM.

In this case, you want to send two responses: one to show the image, another to do the redirect. The only way you can send messages from the server to the client without the client initiating the request is by using @Push.

I explain the same basic concept in this video I made a while back: https://www.youtube.com/watch?v=ZywjOZYWBuQ

So basically you want to do something like this (I don’t have an IDE open so the syntax may not be 100%)

var ui = UI.getCurrent();
Dialog LOADED = new Dialog();
LOADED.setCloseOnOutsideClick(false);
LOADED.setCloseOnEsc(false);
LOADED.add(new Image(imageLink, "Registered Guild!"));
LOADED.open();

// wait 1 second ASYNCHRONOUSLY. 

In the callback for the async wait

ui.access(()-> ui.navigate("/panel/server"));

Alternatively, you can use JavaScript to do the redirect on the client instead.

ohh I see, does this also have to do with my website reloading 3 times before actually showing anything?

Probably not, that sounds like another issue :sweat_smile:

well I’ll look into that later but thanks. I’ll try it out

The way this would look if you didn’t use the async+push workflow is that you would never see the dialog or image. The request would just stall for a second and then redirect you

Yep that’s whats happening

Because the code on the server is synchronous. It would add the dialog, then stall, then navigate and only then send the response to the client.

The video (hopefully) does a better job at explaining the concept than I am right now :smile:

You can try debugging the reloading issue by having your browser dev tools open and checking what’s happening both on the server and the client to see if you spot something odd. Start a new topic for that if you want to discuss it further

well i did what the video said, but the website still stops till the sleep finishes

Dialog LOADED = new Dialog();
            LOADED.setCloseOnOutsideClick(false);
            LOADED.setCloseOnEsc(false);
            LOADED.add(new Image(link, "Registered Guild!"));
            LOADED.open();
            var ui = UI.getCurrent();
            BackendService.waitAsync(5000L).addCallback(result -> ui.access(() -> UI.getCurrent().navigate("/panel/server")), System.out::println);```

BackendService:

public class BackendService {
    @Async
    public static ListenableFuture<Void> waitAsync(Long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            return AsyncResult.forExecutionException(new RuntimeException("Error"));
        }
        return AsyncResult.forValue(null);
    }
}```

Did you remember to add the @Push?

Yes

I saw you put it in MainView but I tried that and it told me to remove it and add it in application.java

Which is what I did

But it still didn’t work