Class Anchor

All Implemented Interfaces:
AttachNotifier, BlurNotifier<Anchor>, DetachNotifier, Focusable<Anchor>, FocusNotifier<Anchor>, HasAriaLabel, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasText, Serializable

@Tag("a") public class Anchor extends HtmlContainer implements Focusable<Anchor>, HasAriaLabel
Component representing an <a> element.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

  • Method Details

    • setHref

      public void setHref(String href)
      Sets the URL that this anchor links to.

      A disabled Anchor removes the attribute from the HTML element, but it is stored (and reused when enabled again) in the server-side component.

      Use the method removeHref() to remove the href attribute instead of setting it to an empty string.

      Parameters:
      href - the href to set
      See Also:
    • removeHref

      public void removeHref()
      Removes href attribute.
      See Also:
    • setHref

      public void setHref(AbstractStreamResource href)
      Sets the URL that this anchor links to with the URL of the given StreamResource.
      Parameters:
      href - the resource value, not null
    • getHref

      public String getHref()
      Gets the URL that this anchor links to.
      Returns:
      the href value, or "" if no href has been set
      See Also:
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class Component
    • setTarget

      public void setTarget(String target)
      Sets the target window, tab or frame for this anchor. The target is either the window.name of a specific target, or one of these special values:
      • _self: Open the link in the current context. This is the default behavior.
      • _blank: Opens the link in a new unnamed context.
      • _parent: Opens the link in the parent context, or the current context if there is no parent context.
      • _top: Opens the link in the top most grandparent context, or the current context if there is no parent context.
      Parameters:
      target - the target value, or "" to remove the target value
    • getTarget

      public Optional<String> getTarget()
      Gets the target window, tab or frame name for this anchor.
      Returns:
      an optional target, or an empty optional if no target has been set
      See Also:
    • setTarget

      public void setTarget(AnchorTargetValue target)
      Sets the target window, tab or frame for this anchor. The target may be the one of these special values:
      • AnchorTarget.DEFAULT: Removes the target value. This has the same effect as setting the target to AnchorTarget.SELF.
      • AnchorTarget.SELF: Opens the link in the current context.
      • AnchorTarget.BLANK: Opens the link in a new unnamed context.
      • AnchorTarget.PARENT: Opens the link in the parent context, or the current context if there is no parent context.
      • AnchorTarget.TOP: Opens the link in the top most grandparent context, or the current context if there is no parent context.
      Parameters:
      target - the target value, not null
    • getTargetValue

      public AnchorTargetValue getTargetValue()
      Gets the target window, tab or frame value for this anchor.
      Returns:
      the target window value , or AnchorTarget.DEFAULT if no target has been set
      See Also: