0

So everything I am finding in my search is how to do it in JS which I know how to do. What I am hoping to find is a GWT mechanism to do this.

What I am looking to do is put an alert window.alert(app.getStatus()) on a page after it loads (not hard). The issue is that with my current code the alert pops-up before the page finishes loading so the user sees a partially loaded white page that does nothing until the Ok button is clicked.

This is what I currently have

public class DisplayApplicationViewImpl extends Composite 
    implements DisplayApplicationView {

    public DisplayApplicationViewImpl() {
        /*...
        Lot of logic that is not helpful
        ...*/

        initWidget(uiBinder.createAndBindUi(this));
        Window.alert("Test");
    }
}

I have also attempted the below (although I do not think it is the correct use) but these only fire once, when an application is opened, and then will not fire on any other applications unless the page is refreshed and still has the load "issue".

Scheduler.get().scheduleFinally(new RepeatingCommand(){
    @Override
    public boolean execute() {
        Window.alert("Test");
        return false;
    }   
});

This one is mildly closer because it allows a loading gif to show but I am not sure why that is there is literally no change in that functionality just this code.

Scheduler.get().scheduleDeferred(new ScheduledCommand(){
    @Override
    public void execute() {
        Window.alert("Test");
    }   
});

I have looked into 'Window.onload()' but that does not seem to be an option where I am.

nerdlyist
  • 2,842
  • 2
  • 20
  • 32

1 Answers1

2

You put your Window.alert() method after initWidget, which means that all UI is built by the time this message is displayed. If you want to make sure that a browser has finished rendering the UI, you can wrap Window.alert() in scheduleDeferred (I explain it here).

Additionally, there may be delays caused by loading data or images. In case of loading data, you can put your Window.alert() in a callback of your data loading method. For images you can use GWT Image widget, which implements HasLoadHandlers interface, but in most cases using scheduleDeferred should be enough.

EDIT:

Each view is only constructed once, so the message only shows up once. This is the correct behavior. If you want to show the message more than once, your presenter/activity should show this message or tell the view to show it.

Community
  • 1
  • 1
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • This is one of the methods I have outlined trying and it is still not letting the page load completely. Also, there is a very odd behavior that this cause the alert to only fire once unless the app (literal web app) is refreshed. I will look into the data loading but why the refresh behavior? – nerdlyist May 13 '16 at 15:40
  • 1. You page is fully loaded *before* your GWT code is even executed. You are talking about the content on your page that GWT code loads. If you load any content asynchronously, you can do something in the callbacks of those methods. – Andrei Volgin May 13 '16 at 20:59
  • 1
    2. Your view is only constructed once, so the message only shows up once. This is the correct behavior. If you want to show the message more than once, your presenter/activity should show this message or tell the view to show it. – Andrei Volgin May 13 '16 at 21:01
  • Your last comment about the presenter/activity was what I seemed to be missing. Can you add that to the answer and I will accept it. – nerdlyist May 14 '16 at 15:03
  • I added the last comment to the answer. – Andrei Volgin May 14 '16 at 17:03