I am looking at History and History JavaDocs in GWT and I notice that there is no way to tell whether the forward or backward button was pressed (either pragmatically or by the user). The "button press" is handled by your registered addValueChangeHandler, but the only thing passed to the handler is a string on your history stack. There is no indication as to whether the "History" is moving "back" (using the back arrow button) or "forward" (using the right arrow button). Is there any way to determine this?
-
Out of curiosity - could provide a reason/use case when such knowledge would be useful? – Igor Klimer Apr 23 '10 at 16:08
-
I want the page transitions to "slide to the left" when you push onto the history stack or press the right-arrow button and "slide to the right" when you pop off of the history stack. Like the iPhone ui. – Stephen Cagle Apr 24 '10 at 14:38
2 Answers
Sorry, you can't. And even if you could, there are browsers, like Firefox, that let the user "jump" back more than one page. So if you try to relying on relative "coordinates" instead of absolute, the navigation could break your app.
You can always append some kind of counter on your history token. It would not be hard, if you have only one history listener.

- 340
- 2
- 8
What you can do is have one UrlManager like this:
public class UrlManager implements ValueChangeHandler<String> {
public UrlManager() {
History.addValueChangeHandler(this);
}
public void onValueChange(ValueChangeEvent<String> event) {
String historyToken = event.getValue();
}
}
Save every history token to a list.
If it is a completely new history token then add it to the list.
If it is the previous history token, then the back button has been pressed.
I suggest using a list to save the tokens and save an iterator that can move up and down the list. So initially it points at the end of the list. If the new token is the previous item on the list, then the back button has been pressed. If you're in the middle of the list (back a few times) and a new entry comes in (new link pressed), remove the rest of the list (can't go forward there anymore) and add the new one- and move iterator to that item.
You get the idea.

- 1,486
- 2
- 16
- 27
-
If it is the previous history token, the forward button might be pressed as well.... – Julia Feb 26 '14 at 14:25