Google Web Toolkit
Search Google Code:

# Class Hyperlink

public class Hyperlink
extends Widget
implements HasHTML, SourcesClickEvents
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, but without reloading the page.

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

- .gwt-Hyperlink { }

### Example

    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, 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);
      }
    }

## Constructors

Hyperlink() | Creates an empty hyperlink.
Hyperlink(String, boolean, String) | Creates a hyperlink with its text and target history token specified.
Hyperlink(String, String) | Creates a hyperlink with its text and target history token specified.

## Methods

addClickListener(ClickListener) | Adds a listener interface to receive click events.
getHTML() | Gets this object's contents as HTML.
getTargetHistoryToken() | Gets the history token referenced by this hyperlink.
getText() | Gets this object's text.
onBrowserEvent(Event) |
removeClickListener(ClickListener) | Removes a previously added listener interface.
setHTML(String) | Sets this object's contents via HTML.
setTargetHistoryToken(String) | Sets the history token referenced by this hyperlink.
setText(String) | Sets this object's text.

## Constructor Detail

### Hyperlink

public Hyperlink()
Creates an empty hyperlink.

### Hyperlink

public Hyperlink(String text, boolean asHTML, 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

### Hyperlink

public Hyperlink(String text, 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

## Method Detail

### addClickListener

public void addClickListener(ClickListener listener)
Adds a listener interface to receive click events.

#### Parameters

listener
  the listener interface to add

### getHTML

public String getHTML()
Gets this object's contents as HTML.

#### Return Value

the object's HTML

### getTargetHistoryToken

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

#### Return Value

the target history token

#### See Also

setTargetHistoryToken

### getText

public String getText()
Gets this object's text.

#### Return Value

the object's text

### onBrowserEvent

public void onBrowserEvent(Event event)

#### Parameters

event

### removeClickListener

public void removeClickListener(ClickListener listener)
Removes a previously added listener interface.

#### Parameters

listener
  the listener interface to remove

### setHTML

public void setHTML(String html)
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 setText(String) whenever possible.

#### Parameters

html
  the object's new HTML

### setTargetHistoryToken

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

#### Parameters

targetHistoryToken
  the new target history token

### setText

public void setText(String text)
Sets this object's text.

#### Parameters

text
  the object's new text