|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.History
public class History
This class allows you to interact with the browser's history stack. Each "item" on the stack is represented by a single string, referred to as a "token". You can create new history items (which have a token associated with them when they are created), and you can programmatically force the current history to move back or forward.
In order to receive notification of user-directed changes to the current
history item, implement the
HistoryListener
interface and attach it
via addHistoryListener(com.google.gwt.user.client.HistoryListener)
.
public class HistoryExample implements EntryPoint, HistoryListener { private Label lbl = new Label(); 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, redirect to a new // 'baz' state. String initToken = History.getToken(); if (initToken.length() == 0) { History.newItem("baz"); } // 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); // Now that we've setup our listener, fire the initial history state. History.fireCurrentHistoryState(); } 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); } }
newItem(String)
to getToken()
/HistoryListener.onHistoryChanged(String)
,
but most will be encoded in the user-visible URL. The following US-ASCII
characters are not encoded on any currently supported browser (but may be in
the future due to future browser changes):
Constructor Summary | |
---|---|
History()
|
Method Summary | |
---|---|
static void |
addHistoryListener(HistoryListener listener)
Adds a listener to be informed of changes to the browser's history stack. |
static void |
back()
Programmatic equivalent to the user pressing the browser's 'back' button. |
static void |
fireCurrentHistoryState()
Fire HistoryListener.onHistoryChanged(String) events with the
current history state. |
static void |
forward()
Programmatic equivalent to the user pressing the browser's 'forward' button. |
static java.lang.String |
getToken()
Gets the current history token. |
static void |
newItem(java.lang.String historyToken)
Adds a new browser history entry. |
static void |
newItem(java.lang.String historyToken,
boolean issueEvent)
Adds a new browser history entry. |
static void |
onHistoryChanged(java.lang.String historyToken)
Deprecated. Use fireCurrentHistoryState() instead. |
static void |
removeHistoryListener(HistoryListener listener)
Removes a history listener. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public History()
Method Detail |
---|
public static void addHistoryListener(HistoryListener listener)
listener
- the listener to be addedpublic static void back()
public static void fireCurrentHistoryState()
HistoryListener.onHistoryChanged(String)
events with the
current history state. This is most often called at the end of an
application's EntryPoint.onModuleLoad()
to inform history listeners of the initial application state.
public static void forward()
public static java.lang.String getToken()
HistoryListener.onHistoryChanged(String)
event for the initial
token; requiring that an application request the token explicitly on
startup gives it an opportunity to run different initialization code in the
presence or absence of an initial token.
public static void newItem(java.lang.String historyToken)
HistoryListener.onHistoryChanged(String)
to be called as well.
historyToken
- the token to associate with the new history itempublic static void newItem(java.lang.String historyToken, boolean issueEvent)
HistoryListener.onHistoryChanged(String)
to be called as well if
and only if issueEvent is true.
historyToken
- the token to associate with the new history itemissueEvent
- true if a
HistoryListener.onHistoryChanged(String)
event should be
issued@Deprecated public static void onHistoryChanged(java.lang.String historyToken)
fireCurrentHistoryState()
instead.
fireCurrentHistoryState()
from the
application EntryPoint.onModuleLoad()
method.
historyToken
- history token to fire events forpublic static void removeHistoryListener(HistoryListener listener)
listener
- the listener to be removed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |