Question

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?

Was it helpful?

Solution

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

OTHER TIPS

I assume you are familiar with GWT Activities and Places design pattern. It provides all the mechanisms you need, namely tokens and mayStop() method in activities.

If I have a view that might have unsaved data, I always implement a hasChanges() method that I call from mayStop() to warn a user if any changes may be lost.

Note that you can make your token as specific as you need. The token may include any information about the page that you need, so you can parse it and act on it. Something like:

myPage.jsp/#CALENDAR:classId=900&option=teachers&menuItem=month

You can easily add a previous page to your token if you need it .

Activities & Places pattern gives me everything I need, and I don't have to worry about history management - I let the browser do it.

The token mechanism is basic but nothing prevents you from building a complex token to represent additional state and to parse it to retrieve that state later. Of course it is limited by the size of the token or URL that browsers support, but you can still do a lot with it. You are right that it doesn't provide much support for more complex things like breadcrumbs and history tracking though. It would require some coding to implement these.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top