简体   繁体   中英

GWT - Trouble with History first token

I have this problem : when i call the Content class (the one who decide which page to view, due to the #param) I do somethings like this :

History.addValueChangeHandler(this);
if(!History.getToken().isEmpty()){
    changePage(History.getToken());
} else {
    History.newItem("homepage");
}

So, now, if i look at browser's navigation bar, i see http://localhost:8084/GWT/?gwt.codesvr=127.0.0.1:9997#homepage . And that's right. Unfortunatly, If i press Back on my browser, i see that it load the previous address, such as http://localhost:8084/GWT/?gwt.codesvr=127.0.0.1:9997

I have a sort of "fake" page at the beginning.

1 - How can I fix it? And start the application with a default token, or remove it in the history. Or just call the onValueChange method when there is empty token, and after decide the workflow with a sort of switch/if-else.

2 - As related question, when i call History.addValueChangeHandler(this); in the costructor class, netbeans say "Leaking this in constructor". What it means?

Cheers

Maybe you forgot to add History.fireCurrentHistoryState(); to end of onModuleLoad() method?

You need to set a history token and fire the history change event with current token. Heres how you could do it:

/ If the application starts with no history token, redirect to a new
// 'homepage' state.
String initToken = History.getToken();
if (initToken.length() == 0) {
  History.newItem("homepage");
}

// Add widgets etc


// Add history listener
History.addHistoryListener(yourHistoryHandler);

// Fire the initial history state.
History.fireCurrentHistoryState();

IMHO, home url in form of "proto://hostname#homepage" is ugly :)

1. Just a suggestion:

String token = History.getToken();
String page = token.isEmpty() ? "homepage" : token;
changePage(page);

2. Does Your EntryPoint implement ValueChangeHandler<String> ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM