Class BreadcrumbsItem

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.breadcrumbs.BreadcrumbsItem
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasEnabled, HasStyle, HasText, HasPrefix, Serializable

@Tag("vaadin-breadcrumbs-item") @NpmPackage(value="@vaadin/breadcrumbs", version="25.2.0") @JsModule("@vaadin/breadcrumbs/src/vaadin-breadcrumbs-item.js") public class BreadcrumbsItem extends Component implements HasText, HasEnabled, HasPrefix
An item of the Breadcrumbs component, representing a single entry in the navigation trail.

An item carries the text shown in the trail and, optionally, a path it links to. An item without a path is the current page and is rendered as a non-link. The link target can be set as a plain URL string via setPath(String) or resolved from a Flow route class via setPath(Class) / setPath(Class, RouteParameters). An optional prefix component (typically an icon) can be shown before the text.

Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • BreadcrumbsItem

      public BreadcrumbsItem(String text)
      Creates a breadcrumbs item with the given text and no path. An item without a path represents the current page and is rendered as a non-link.
      Parameters:
      text - the text of the item
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, String path)
      Creates a breadcrumbs item with the given text that links to the given path.
      Parameters:
      text - the text of the item
      path - the path to link to
      Throws:
      IllegalArgumentException - if path uses a scheme that is not considered safe; see setUnsafePath(String) and the "com.vaadin.safeUrlSchemes" configuration property
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, Class<? extends Component> view)
      Creates a breadcrumbs item with the given text that links to the given view.
      Parameters:
      text - the text of the item
      view - the view to link to
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, Class<? extends Component> view, RouteParameters params)
      Creates a breadcrumbs item with the given text that links to the given view using the given route parameters.
      Parameters:
      text - the text of the item
      view - the view to link to
      params - the route parameters
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, String path, Component prefixComponent)
      Creates a breadcrumbs item with the given text and prefix component (like an icon) that links to the given path.
      Parameters:
      text - the text of the item
      path - the path to link to
      prefixComponent - the prefix component for the item (usually an icon)
      Throws:
      IllegalArgumentException - if path uses a scheme that is not considered safe; see setUnsafePath(String) and the "com.vaadin.safeUrlSchemes" configuration property
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, Class<? extends Component> view, Component prefixComponent)
      Creates a breadcrumbs item with the given text and prefix component (like an icon) that links to the given view.
      Parameters:
      text - the text of the item
      view - the view to link to
      prefixComponent - the prefix component for the item (usually an icon)
    • BreadcrumbsItem

      public BreadcrumbsItem(String text, Class<? extends Component> view, RouteParameters params, Component prefixComponent)
      Creates a breadcrumbs item with the given text and prefix component (like an icon) that links to the given view using the given route parameters.
      Parameters:
      text - the text of the item
      view - the view to link to
      params - the route parameters
      prefixComponent - the prefix component for the item (usually an icon)
  • Method Details

    • setText

      public void setText(String text)
      Sets the given string as the text content of this item.

      This method removes any existing content in the default slot and replaces it with the given text. Other slotted children (such as the prefix) are preserved.

      Specified by:
      setText in interface HasText
      Parameters:
      text - the text content to set, or null to remove existing text
    • getText

      public String getText()
      Description copied from interface: HasText
      Gets the text content of this component. This method only considers the text of the actual component. The text contents of any child components or elements are not considered.
      Specified by:
      getText in interface HasText
      Returns:
      the text content of this component, not null
    • bindText

      public SignalBinding<String> bindText(Signal<String> textSignal)
      Description copied from interface: HasText
      Binds a Signal's value to the text content of this component. The text content is set immediately with the current signal value when the binding is created, and is kept synchronized with any subsequent signal value changes while the element is in attached state. When the element is in detached state, signal value changes have no effect. null signal unbinds the existing binding.

      While a Signal is bound, any attempt to set the text content manually throws BindingActiveException. Same happens when trying to bind a new Signal while one is already bound.

      Example of usage:

       ValueSignal<String> signal = new ValueSignal<>("");
       Span component = new Span("");
       add(component);
       component.bindText(signal);
       signal.set("text"); // The component text content is set to "text"
       
      Specified by:
      bindText in interface HasText
      Parameters:
      textSignal - the signal to bind, not null
      See Also:
    • getPath

      public String getPath()
      Gets the path this item links to.
      Returns:
      the path this item links to, or null if the item has no path
    • setPath

      public void setPath(String path)
      Sets the path, as a URL string, this item links to.

      Note that there is also an alternative way of setting the link path via setPath(Class).

      Parameters:
      path - the path to link to, or null to remove the path and render the item as the current page (a non-link)
      See Also:
    • setUnsafePath

      public void setUnsafePath(String path)
      Sets the path this item links to without validating its scheme.

      Unlike setPath(String), this method does not reject paths based on the "com.vaadin.safeUrlSchemes" configuration. Use it only for paths that are fully under your control and known to be safe, such as a hard-coded javascript: URL. Passing untrusted input here can expose the application to cross-site scripting (XSS) attacks.

      Parameters:
      path - the path to link to, or null to remove the path and render the item as the current page (a non-link)
      See Also:
    • setPath

      public void setPath(Class<? extends Component> view)
      Resolves the URL of the given view via the Vaadin router and sets it as the path this item links to.
      Parameters:
      view - the view to link to. The view should be annotated with the Route annotation. Set to null to remove the path.
      See Also:
    • setPath

      public void setPath(Class<? extends Component> view, RouteParameters parameters)
      Resolves the URL of the given view via the Vaadin router using the given route parameters and sets it as the path this item links to.
      Parameters:
      view - the view to link to. The view should be annotated with the Route annotation. Set to null to remove the path.
      parameters - the route parameters
      See Also: