GWT 2.0.3

com.google.gwt.user.client.ui
Class Hyperlink

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Hyperlink
All Implemented Interfaces:
HasClickHandlers, HasHandlers, EventListener, HasHTML, HasText, SourcesClickEvents
Direct Known Subclasses:
InlineHyperlink

public class Hyperlink
extends Widget
implements HasHTML, SourcesClickEvents, HasClickHandlers

A widget that serves as an "internal" hyperlink. That is, it is a link to another state of the running application. When clicked, it will create a new history frame using History.newItem(java.lang.String), but without reloading the page.

If you want an HTML hyperlink (<a> tag) without interacting with the history system, use Anchor instead.

Being a true hyperlink, it is also possible for the user to "right-click, open link in new window", which will cause the application to be loaded in a new window at the state specified by the hyperlink.

CSS Style Rules

Example

public class HistoryExample implements EntryPoint, ValueChangeHandler {

  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.addValueChangeHandler(this);

    // Now that we've setup our listener, fire the initial history state.
    History.fireCurrentHistoryState();
  }

  public void onValueChange(ValueChangeEvent event) {
    // 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: " + event.getValue());
  }
}

See Also:
Anchor

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
  Hyperlink()
          Creates an empty hyperlink.
protected Hyperlink(Element elem)
           
  Hyperlink(java.lang.String text, boolean asHTML, java.lang.String targetHistoryToken)
          Creates a hyperlink with its text and target history token specified.
  Hyperlink(java.lang.String text, java.lang.String targetHistoryToken)
          Creates a hyperlink with its text and target history token specified.
 
Method Summary
 HandlerRegistration addClickHandler(ClickHandler handler)
          Deprecated. Use FocusWidget.addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.
 void addClickListener(ClickListener listener)
          Deprecated. Use FocusWidget.addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.
 java.lang.String getHTML()
          Gets this object's contents as HTML.
 java.lang.String getTargetHistoryToken()
          Gets the history token referenced by this hyperlink.
 java.lang.String getText()
          Gets this object's text.
 void onBrowserEvent(Event event)
          Fired whenever a browser event is received.
protected  void onEnsureDebugId(java.lang.String baseID)
          Affected Elements: -wrapper = the div around the link.
 void removeClickListener(ClickListener listener)
          Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead
 void setHTML(java.lang.String html)
          Sets this object's contents via HTML.
 void setTargetHistoryToken(java.lang.String targetHistoryToken)
          Sets the history token referenced by this hyperlink.
 void setText(java.lang.String text)
          Sets this object's text.
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addDomHandler, addHandler, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

Hyperlink

public Hyperlink()
Creates an empty hyperlink.


Hyperlink

public Hyperlink(java.lang.String text,
                 boolean asHTML,
                 java.lang.String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.

Parameters:
text - the hyperlink's text
asHTML - true to treat the specified text as html
targetHistoryToken - the history token to which it will link
See Also:
setTargetHistoryToken(java.lang.String)

Hyperlink

public Hyperlink(java.lang.String text,
                 java.lang.String targetHistoryToken)
Creates a hyperlink with its text and target history token specified.

Parameters:
text - the hyperlink's text
targetHistoryToken - the history token to which it will link, which may not be null (use Anchor instead if you don't need history processing)

Hyperlink

protected Hyperlink(Element elem)
Method Detail

addClickHandler

@Deprecated
public HandlerRegistration addClickHandler(ClickHandler handler)
Deprecated. Use FocusWidget.addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.

Description copied from interface: HasClickHandlers
Adds a ClickEvent handler.

Specified by:
addClickHandler in interface HasClickHandlers
Parameters:
handler - the click handler
Returns:
HandlerRegistration used to remove this handler

addClickListener

@Deprecated
public void addClickListener(ClickListener listener)
Deprecated. Use FocusWidget.addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.

Description copied from interface: SourcesClickEvents
Adds a listener interface to receive click events.

Specified by:
addClickListener in interface SourcesClickEvents
Parameters:
listener - the listener interface to add

getHTML

public java.lang.String getHTML()
Description copied from interface: HasHTML
Gets this object's contents as HTML.

Specified by:
getHTML in interface HasHTML
Returns:
the object's HTML

getTargetHistoryToken

public java.lang.String getTargetHistoryToken()
Gets the history token referenced by this hyperlink.

Returns:
the target history token
See Also:
setTargetHistoryToken(java.lang.String)

getText

public java.lang.String getText()
Description copied from interface: HasText
Gets this object's text.

Specified by:
getText in interface HasText
Returns:
the object's text

onBrowserEvent

public void onBrowserEvent(Event event)
Description copied from interface: EventListener
Fired whenever a browser event is received.

Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class Widget
Parameters:
event - the event received

removeClickListener

@Deprecated
public void removeClickListener(ClickListener listener)
Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead

Description copied from interface: SourcesClickEvents
Removes a previously added listener interface.

Specified by:
removeClickListener in interface SourcesClickEvents
Parameters:
listener - the listener interface to remove

setHTML

public void setHTML(java.lang.String html)
Description copied from interface: HasHTML
Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using HasText.setText(String) whenever possible.

Specified by:
setHTML in interface HasHTML
Parameters:
html - the object's new HTML

setTargetHistoryToken

public void setTargetHistoryToken(java.lang.String targetHistoryToken)
Sets the history token referenced by this hyperlink. This is the history token that will be passed to History.newItem(java.lang.String) when this link is clicked.

Parameters:
targetHistoryToken - the new history token, which may not be null (use Anchor instead if you don't need history processing)

setText

public void setText(java.lang.String text)
Description copied from interface: HasText
Sets this object's text.

Specified by:
setText in interface HasText
Parameters:
text - the object's new text

onEnsureDebugId

protected void onEnsureDebugId(java.lang.String baseID)
Affected Elements:

Overrides:
onEnsureDebugId in class UIObject
Parameters:
baseID - the base ID used by the main element
See Also:
UIObject.onEnsureDebugId(String)

GWT 2.0.3