gwtgwt-history

Handling GWT History and Fragment Identifiers


I have a GWT application that accept these tokens:

http://127.0.0.1:8888/app.html?gwt.codesvr=127.0.0.1:9997#user&someuser

This will open up a view (as in MVC) which works just fine. However, the problem is that the view has menus that can trigger to change to another view, like to switch to the user profile, etc. The URL above sticks but the content of the page is completely changed.

Is there a way to handle browser back button in this case. Back button works fine switching back to views triggered by URL fragments (by typing in the Browser address bar), like switching to #user&someuser to #profile

A problem however when the view is changed from menu or button events. Is there a way to emulate the same effect as if user has typed URL fragments manually? Such that back button will work. BTW, each URL fragment is associated to one view.


Solution

  • You're probably looking for History.newItem(newToken) (or History.newItem(newtoken, false) if you don't want it to fire an event).

    If it's not too late in your project, I'd suggest you use GWT Places though instead of History, and possibly GWT Activities (depending on your needs).
    I wrote a few articles about these a while back, when they were introduced into GWT 2.1: