Interface HasText

All Superinterfaces:
HasElement, Serializable
All Known Implementing Classes:
HtmlContainer, RouterLink, Text

public interface HasText extends HasElement
A component that supports text content.

HasText is generally implemented by components whose primary function is to have textual content. It isn't implemented for example by layouts since setText(String) will remove all existing child components and child elements. To mix text and child components in a component that also supports child components, use HasComponents.add(Component...) with the Text component for the textual parts.

The default implementations set the text as text content of HasElement.getElement(). Override all methods in this interface if the text should be added to some other element.

Since:
1.0
Author:
Vaadin Ltd
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Represents "white-space" style values.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    bindText(com.vaadin.signals.Signal<String> textSignal)
    Binds a Signal's value to the text content of this component and keeps the text content synchronized with the signal value while the element is in attached state.
    default String
    Gets the text content of this component.
    Gets the "white-space" style value.
    default void
    Sets the given string as the content of this component.
    default void
    Sets the given value as "white-space" style value.

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

    getElement
  • Method Details

    • setText

      default void setText(String text)
      Sets the given string as the content of this component. This removes any existing child components and child elements. To mix text and child components in a component that also supports child components, use HasComponents.add(Component...) with the Text component for the textual parts.
      Parameters:
      text - the text content to set
    • getText

      default String getText()
      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.
      Returns:
      the text content of this component, not null
    • setWhiteSpace

      default void setWhiteSpace(HasText.WhiteSpace value)
      Sets the given value as "white-space" style value.
      Parameters:
      value - the "white-space" style value, not null
    • getWhiteSpace

      default HasText.WhiteSpace getWhiteSpace()
      Gets the "white-space" style value.

      The default value is WhiteSpace#NORMAL. If the "white-space" style value is non standard then null is returned.

      Returns:
      the "white-space" style value, may be null
    • bindText

      default void bindText(com.vaadin.signals.Signal<String> textSignal)
      Binds a Signal's value to the text content of this component and keeps the text content synchronized with the signal value 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.value("text"); // The component text content is set to "text"
       
      Parameters:
      textSignal - the signal to bind or null to unbind any existing binding
      Throws:
      com.vaadin.signals.BindingActiveException - thrown when there is already an existing binding
      See Also: