Re: clearing the history on page refresh

213 views
Skip to first unread message

Thomas Broyer

unread,
Oct 17, 2012, 2:25:49 PM10/17/12
to google-we...@googlegroups.com
The Right Way™ is to handle the token at application start. If you use History, then call History.fireCurrentHistoryState() from your onModuleStart; if you use places, call handleCurrentHistory() on your PlaceHistoryHandler.
It's not only about "history" and the "back button", it's about making URLs to get you where you want/need within your app!

On Wednesday, October 17, 2012 8:03:25 PM UTC+2, lexl wrote:
Hi,

I have a simple stateless app, with what I hope is a simple problem, but I can't find an answer.

On the main page is a button (Foo), when you click the button the history is updated with a new token #foo, and the url becomes myapp.com#foo.  So far so good.

When you hit refresh, GWT reloads the main page. No problem. However the displayed url remains myapp.com#foo. and #foo continues to live in the history stack, so that if I click the Foo button now, nothing happens. The user stays on the main page.

What's the right way to clear the history on a refresh or otherwise work around this problem?  The questions and answers I've seen have all talked about synching server state, refreshing javascript state, etc. I don't have any of those issues, I just need to clear the history or otherwise make the button work, even if the token is already at the top of the history stack.

thanks.

lexl

unread,
Oct 17, 2012, 2:56:09 PM10/17/12
to google-we...@googlegroups.com
I'm using History.  Below is the code from my onModuleLoad(). I added the fireCurrentHistoryState() call as you suggested (thank you), but I'm having the same problem.  After a refresh on a different page, I'm returned to the main page, where I click the same button. The click handler calls 

History.newItem("Foo");

but  my valueChangeHandler doesn't get invoked.

  public void onModuleLoad() {
    clientFactory = ClientFactoryImpl.getInstance();

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

    History.addValueChangeHandler(new ValueChangeHandler<String>() {
      @Override
      public void onValueChange(ValueChangeEvent<String> event) {
        String token = event.getValue();
        handleHistoryToken(token);
      }
    });
    History.fireCurrentHistoryState();
    RootPanel.get().add(mainPanel);

lexl

unread,
Oct 17, 2012, 3:44:31 PM10/17/12
to google-we...@googlegroups.com
I seem to have got it sorted now.  Moving the fireCurrentHistoryState() method to the bottom of the onModuleLoad() seems to have helped, along with a change to my token parsing logic.

thanks for your help
Reply all
Reply to author
Forward
0 new messages