Question

I have a method in a class that implements ValueChangeHandler<String> this class is initialised from within the onModuleLoad() method like so

mainController = new MainController();
History.addValueChangeHandler(mainController);
mainController.initialise(History.getToken());

And the initialise() method looks like this;

public void initialise(String initialToken) {
    if (initialToken.equals("")) {
        History.newItem(String.valueOf(HistoryTokens.MAIN_PAGE), true);
    } else {
        History.newItem(initialToken, true);
    }
}

When the app is started with a blank history token, ie when Launch Default Browser is pressed then the onValueChange() method is called, changing the url whilst the app is running calls the onValueChange() method.

However, entering a URL in a blank browser tab with a token in the URL, ie http://127.0.0.1:8888/MyApp.html?gwt.codesvr=127.0.0.1:9997#mjh&jdfhfh=786543, does not call the onValueChange() method. I'm confused as I hit the History.newItem(initialToken, true); part of the if statement. I thought that this would ensure that onValueChange() was called. What's going wrong?

Was it helpful?

Solution

You should always call the History.fireCurrentHistoryState() at the end of your GWT onModuleLoad(). I think that should solve your problem.

The thing is that the first history event ( like when you load page.com/#xyz ) is not captured by the ValueChangeHandler, you have to "fake it" with the History.fireCurrentHistoryState()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top