How do I determine if I will go “forward” or “backward” through my story in GWT?

I look at History and JavaDocs History in GWT, and I notice that it is not possible to indicate whether a button has been pressed forward or backward (either pragmatically or by the user). The button click is handled by the registered addValueChangeHandler, but the only thing passed to the handler is the line in your history stack. There is no indication as to whether History moves backward (using the back arrow button) or forward (using the right arrow button). Is there any way to determine this?

+4
source share
2 answers

Sorry, you can’t. And even if you could, there are browsers such as Firefox that allow the user to "jump" back more than one page. Therefore, if you try to use relative "coordinates" instead of absolute, the navigation system may break your application.

You can always add some kind of counter to your token. It would not be difficult if you have only one listener to the story.

+4
source

What you can do is one UrlManager:

public class UrlManager implements ValueChangeHandler<String> { public UrlManager() { History.addValueChangeHandler(this); } public void onValueChange(ValueChangeEvent<String> event) { String historyToken = event.getValue(); } } 

Save each history token in a list.
If this is a brand new history marker, add it to the list. If this is the previous history token, the back button has been pressed.

I suggest using a list to save tokens and save an iterator that can move up and down the list. Therefore, it initially points to the end of the list. If the new token is the previous item in the list, then the "Back" button is pressed. If you are in the middle of the list (several times back) and a new entry appears (a new link is clicked), delete the rest of the list (you can no longer go there) and add new ones and move the iterator to this element.

You get the idea.

0
source

Source: https://habr.com/ru/post/1307716/


All Articles