I'm trying to add history capabilities to my GWT app.
To my understanding, the basic history support that GWT has to offer is indeed basic... or should I say very basic.
It doesn't really store any additional information about the state other than the token that is currently at the top of the stack. Meaning I would expect getting information like popped out token which is the one we just left & also maybe getting info whether back or forward was pressed.
The basic mechanism assumes that there is no 'advanced' state for pages, i.e. if current token is 'menu' then it doesn't matter where we are coming from to this menu page. However, I would like to check whether we're leaving a specific page at this moment because if we do then I would like to show a warning to save data first.
Furthermore, some of my pages are not using default constructors but instead, get specific information from the currently displayed page. This prevents me from having a centralized place where all pages are created and all the buttons in the app are just playing around with the history token. (As advised here for example on page 37.)
Anyways, I'm pretty lost here. I'm not sure what path to take in order to achieve basic support for back/forward without rewriting my app.
Anyone thoughts or ideas?
If you need to track were you come from, you can easily do it yourself: it's as easy as storing the token in a global state and only updating it after you actioned on the new one.
FYI, PlaceController
does just that (using a Place
abstraction rather than string-based tokens). It also fires a PlaceChangeRequestEvent
on which you can setMessage
to ask the user for confirmation before actually doing the move (PlaceChangeEvent
).
I'm not suggesting you move to using PlaceController
rather than raw History
(even though I'm sure you wouldn't regret it), just pointing out that this is possible.
See also How do I determine whether I am going "forward" or "backward" through my History in GWT? and GWT 2.1 Place/Activity technique glitch: URL changes before navigation is confirmed