Hello,

For example take the example in the documentation:
https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsHistory
 
In short, it is a tab panel with 3 tabs, and history functionality is added 
so you can use back and forth browser buttons to navigate to previous/next 
tab.

I'll focus on the following 2 parts of the code:

1. adding corresponding token to history stack when pressing opening a tab

tabPanel.addSelectionHandler(new SelectionHandler<Integer>(){
      public void onSelection(SelectionEvent<Integer> event) {
        History.newItem("page" + event.getSelectedItem());
      }});

2. When back and forward button is clicked navigate to the correct tab:

public void onValueChange(ValueChangeEvent<String> event) {
        String historyToken = event.getValue();

        // Parse the history token
        try {
          if (historyToken.substring(0, 4).equals("page")) {
            String tabIndexToken = historyToken.substring(4, 5);
            int tabIndex = Integer.parseInt(tabIndexToken);
            // Select the specified tab panel
            tabPanel.selectTab(tabIndex);
          } else {
            tabPanel.selectTab(0);
          }

        } catch (IndexOutOfBoundsException e) {
          tabPanel.selectTab(0);
        }
      }


And here comes the question again: Why when i push a history token on the 
stack (when opening a tab), is the "onvaluechange" operation triggered.
It seems unnecessary to me. The tab is opened because you click it's title, 
and then it is opened again because of the onvalueChange operation.
I'm aware of the History.newItem(token, false) operation - which i am 
currently using -  to avoid calling the onvaluechange() operation, but why 
is this not default behavior, I just don't see why you would need to call 
that operation.

Your thoughts are very appreciated :)

Regards,

Ruben

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to