开发者

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 :

Histor开发者_开发知识库y.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>?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜