Class Hyperlink

All Implemented Interfaces:
HasClickHandlers, HasAttachHandlers, HasHandlers, HasDirectionEstimator, HasSafeHtml, EventListener, HasDirectionalSafeHtml, HasDirectionalText, HasHTML, HasText, HasVisibility, IsWidget, SourcesClickEvents
Direct Known Subclasses:
InlineHyperlink

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.

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by setDirectionEstimator(boolean) or passing a DirectionEstimator parameter to the constructor, and is off by default.

CSS Style Rules

  • .gwt-Hyperlink { }

Example

public class HistoryExample implements EntryPoint, ValueChangeHandler<String> {

  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<String> 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:
  • Field Details

  • Constructor Details

    • Hyperlink

      public Hyperlink()
      Creates an empty hyperlink.
    • Hyperlink

      public Hyperlink(SafeHtml html, String targetHistoryToken)
      Creates a hyperlink with its html and target history token specified.
      Parameters:
      html - the hyperlink's safe html
      targetHistoryToken - the history token to which it will link
      See Also:
    • Hyperlink

      public Hyperlink(SafeHtml html, HasDirection.Direction dir, String targetHistoryToken)
      Creates a hyperlink with its html and target history token specified.
      Parameters:
      html - the hyperlink's safe html
      dir - the html's direction
      targetHistoryToken - the history token to which it will link
      See Also:
    • Hyperlink

      public Hyperlink(SafeHtml html, DirectionEstimator directionEstimator, String targetHistoryToken)
      Creates a hyperlink with its html and target history token specified.
      Parameters:
      html - the hyperlink's safe html
      directionEstimator - A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
      targetHistoryToken - the history token to which it will link
      See Also:
    • 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, which may not be null (use Anchor instead if you don't need history processing)
    • Hyperlink

      public Hyperlink(String text, HasDirection.Direction dir, String targetHistoryToken)
      Creates a hyperlink with its text and target history token specified.
      Parameters:
      text - the hyperlink's text
      dir - the text's direction
      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

      public Hyperlink(String text, DirectionEstimator directionEstimator, String targetHistoryToken)
      Creates a hyperlink with its text and target history token specified.
      Parameters:
      text - the hyperlink's text
      directionEstimator - A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.
      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

      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:
    • Hyperlink

      protected Hyperlink(Element elem)
  • Method Details