To the user, the history token appears in the browser address bar
Web anchors like a name=”stuff” and
corresponding links like a href=”#stuff” as part of the URL, as in http://www.gwtpowered.org/#Xyzzy. If
do not affect the GWT history stack. However
the user browses to that address, the GWT application is loaded and
you should avoid using them in a GWT
can call History.getToken( ) to see what it’s supposed to do.
application. If the user bookmarked a URL with
a web anchor, when they reloaded that page
GWT would interpret the anchor as a history Internally, history is managed by a special iframe tag that you
token. It would pass the token to your listener,
put in your application’s HTML page. The GWT scaffolding script
which wouldn’t know how to handle it. If you
adds this for you automatically:
really want to change states, use the Hyperlink
class instead.
package com.eEcho.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.HistoryListener;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;/**
* Entry point classes defineonModuleLoad().
*/
public class historyTest implements EntryPoint, HistoryListener {
private Label lbl = new Label();/**
* This is the entry point method.
*/
public void onModuleLoad() {
// Create three hyperlinks that change the application’s history.
Hyperlink link0 = new Hyperlink(”link to foo”, “foo”);
Hyperlink link1 = new Hyperlink(”link to bar”, “bar”);
Hyperlink link2 = new Hyperlink(”link to baz”, “baz”);// If the application starts with no history token, start it off in the
// ‘baz’ state.
String initToken = History.getToken();
if (initToken.length() == 0)
initToken = “baz”;// onHistoryChanged() is not called when the application first runs. Call
// it now in order to reflect the initial state.
onHistoryChanged(initToken);// Add widgets to the root panel.
VerticalPanel panel = new VerticalPanel();
panel.add(lbl);
panel.add(link0);
panel.add(link1);
panel.add(link2);
RootPanel.get().add(panel);// Add history listener
History.addHistoryListener(this);
}public void onHistoryChanged(String historyToken) {
// This method is called whenever the application’s history changes. Set
// the label to reflect the current history token.
lbl.setText(”The current history token is: ” + historyToken);
}
}
Add A Comment
You must be logged in to post a comment.
