Class Anchor

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.HtmlContainer
com.vaadin.flow.component.html.Anchor
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<Anchor>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<Anchor>, com.vaadin.flow.component.FocusNotifier<Anchor>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, Serializable

@Tag("a") public class Anchor extends com.vaadin.flow.component.HtmlContainer implements com.vaadin.flow.component.Focusable<Anchor>, com.vaadin.flow.component.HasAriaLabel
Component representing an <a> element.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText

    com.vaadin.flow.component.HasText.WhiteSpace
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty anchor component.
    Anchor(com.vaadin.flow.server.AbstractStreamResource href, String text)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Anchor(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, AttachmentType attachmentType, String text)
    Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.
    Anchor(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, String text)
    Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor.
    Anchor(String href, com.vaadin.flow.component.Component... components)
    Creates an anchor component with the given href and components as children of this component.
    Anchor(String href, String text)
    Creates an anchor component with the given text content and href.
    Anchor(String href, String text, AnchorTarget target)
    Creates an anchor component with the given target, text content and href.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the URL that this anchor links to.
    Gets the target window, tab or frame name for this anchor.
    Gets the target window, tab or frame value for this anchor.
    boolean
    Check if the anchor target will be downloaded for a click.
    boolean
    Checks if this anchor should be ignored by the Vaadin router.
    void
    onEnabledStateChanged(boolean enabled)
     
    void
    Removes href attribute.
    void
    setDownload(boolean download)
    Set the download state of the anchor.
    void
    setHref(com.vaadin.flow.server.AbstractStreamResource href)
    Deprecated, for removal: This API element is subject to removal in a future version.
    void
    setHref(com.vaadin.flow.server.streams.DownloadHandler downloadHandler)
    Sets the URL that this anchor links to and that is bound to a given DownloadHandler callback on the server for handling data download from the server to the client when clicking an anchor.
    void
    setHref(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, AttachmentType attachmentType)
    Sets the URL that this anchor links to and that is bound to a given DownloadHandler callback on the server for handling data download from the server to the client when clicking an anchor.
    void
    Sets the URL that this anchor links to.
    void
    setRouterIgnore(boolean ignore)
    The routing mechanism in Vaadin by default intercepts all anchor elements with relative URL.
    void
    Sets the target window, tab or frame for this anchor.
    void
    setTarget(String target)
    Sets the target window, tab or frame for this anchor.

    Methods inherited from class com.vaadin.flow.component.HtmlComponent

    getTitle, setTitle

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasAriaLabel

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasText

    getText, getWhiteSpace, setText, setWhiteSpace
  • Constructor Details

    • Anchor

      public Anchor()
      Creates a new empty anchor component.
    • Anchor

      public Anchor(String href, String text)
      Creates an anchor component with the given text content and href.
      Parameters:
      href - the href to set
      text - the text content to set
      See Also:
    • Anchor

      public Anchor(String href, String text, AnchorTarget target)
      Creates an anchor component with the given target, text content and href.
      Parameters:
      href - the href to set
      text - the text content to set
      target - the target window, tab or frame
      See Also:
    • Anchor

      @Deprecated(since="24.8", forRemoval=true) public Anchor(com.vaadin.flow.server.AbstractStreamResource href, String text)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates an anchor component with the given text content and stream resource.
      Parameters:
      href - the resource value, not null
      text - the text content to set
      See Also:
    • Anchor

      public Anchor(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, String text)
      Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor. Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler. For custom handlers the mode AttachmentType.DOWNLOAD will be set.
      Parameters:
      downloadHandler - the callback that handles data download, not null
      text - the text content to set
      See Also:
    • Anchor

      public Anchor(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, AttachmentType attachmentType, String text)
      Creates an anchor component with the given text content and a callback that handles data download from the server to the client when clicking an anchor. Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler. LinkMode determines if the attribute `download` should be set or not. AttachmentType.DOWNLOAD will set the download attribute, where as AttachmentType.INLINE will remove it.
      Parameters:
      downloadHandler - the callback that handles data download, not null
      attachmentType - set the correct attribute for anchor according to given mode, null will set type to AttachmentType.DOWNLOAD
      text - the text content to set
      See Also:
    • Anchor

      public Anchor(String href, com.vaadin.flow.component.Component... components)
      Creates an anchor component with the given href and components as children of this component.
      Parameters:
      href - the href to set
      components - the components to add
      See Also:
  • 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

      @Deprecated(since="24.8", forRemoval=true) public void setHref(com.vaadin.flow.server.AbstractStreamResource href)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the URL that this anchor links to with the URL of the given StreamResource.
      Parameters:
      href - the resource value, not null
    • setHref

      public void setHref(com.vaadin.flow.server.streams.DownloadHandler downloadHandler)
      Sets the URL that this anchor links to and that is bound to a given DownloadHandler callback on the server for handling data download from the server to the client when clicking an anchor. Sets the 'download' attribute for link when given a non-inline handler implementing AbstractDownloadHandler.
      Parameters:
      downloadHandler - the callback that handles data download, not null
    • setHref

      public void setHref(com.vaadin.flow.server.streams.DownloadHandler downloadHandler, AttachmentType attachmentType)
      Sets the URL that this anchor links to and that is bound to a given DownloadHandler callback on the server for handling data download from the server to the client when clicking an anchor. LinkMode determines if the attribute `download` should be set or not. AttachmentType.DOWNLOAD will set the download attribute, where as AttachmentType.INLINE will remove it.
      Parameters:
      downloadHandler - the callback that handles data download, not null
      attachmentType - set the correct attribute for anchor according to given mode, null will set the type to AttachmentType.DOWNLOAD
    • setDownload

      public void setDownload(boolean download)
      Set the download state of the anchor. true will add the download attribute making the anchor target to be downloaded on click. false will remove the download attribute.
      Parameters:
      download - true to add the 'download' attribute and false to remove it
    • isDownload

      public boolean isDownload()
      Check if the anchor target will be downloaded for a click.
      Returns:
      true if download is set for this anchor
    • setRouterIgnore

      public void setRouterIgnore(boolean ignore)
      The routing mechanism in Vaadin by default intercepts all anchor elements with relative URL. This method can be used make the router ignore this anchor and this way make this anchor behave normally and cause a full page load.
      Parameters:
      ignore - true if this link should not be intercepted by the single-page web application routing mechanism in Vaadin.
    • isRouterIgnore

      public boolean isRouterIgnore()
      Checks if this anchor should be ignored by the Vaadin router.
      Returns:
      true if this anchor should be ignored by the Vaadin router and behave normally.
    • 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 com.vaadin.flow.component.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: