Class FieldSet

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasAriaLabel, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasText, Serializable

@Tag("fieldset") public class FieldSet extends HtmlContainer implements HasAriaLabel
Represents an HTML <fieldset> element. This component is used to group several UI components within a form, enhancing form accessibility and organization.
See Also:
  • Constructor Details

    • FieldSet

      public FieldSet()
      Creates a new fieldset with an empty legend.
    • FieldSet

      public FieldSet(String legendText)
      Creates a new fieldset with the given legend text.
      Parameters:
      legendText - the legend text to set.
    • FieldSet

      public FieldSet(Signal<String> textSignal)
      Creates a new fieldset with its legend text bound to the given signal.
      Parameters:
      textSignal - the legend text signal to bind to, not null
      See Also:
    • FieldSet

      public FieldSet(Component... content)
      Creates a new fieldset with the given content.
      Parameters:
      content - the content component to set.
    • FieldSet

      public FieldSet(String legendText, Component content)
      Creates a new fieldset using the provided legend text and content.
      Parameters:
      legendText - the legend text to set.
      content - the content component to set.
  • Method Details

    • getLegend

      public FieldSet.Legend getLegend()
      Returns the legend component associated with this fieldset.
      Returns:
      the legend component.
    • setLegendText

      public void setLegendText(String text)
      Sets the text of the legend.
      Parameters:
      text - the text to set.
    • getLegendText

      public String getLegendText()
      Gets the text of the legend.
      Returns:
      the text of the legend, or null if no legend is present.
    • bindLegendText

      public void bindLegendText(Signal<String> legendTextSignal)
      Binds a signal's value to the fieldset legend text so that the legend is updated when the signal's value is updated.

      Passing null as the signal removes any existing binding for the legend text. When unbinding, the current legend text is left unchanged.

      While a binding for the legend text is active, any attempt to set the legend text manually via setLegendText(String) throws BindingActiveException. The same happens when trying to bind a new Signal while one is already bound.

      Bindings are lifecycle-aware and only active while this component is in the attached state; they are deactivated while the component is in the detached state.

      Parameters:
      legendTextSignal - the signal to bind or null to unbind any existing binding
      Throws:
      BindingActiveException - thrown when there is already an existing binding
      Since:
      25.1
      See Also:
    • getContent

      public Stream<Component> getContent()
      Returns the content of the fieldset.
      Returns:
      Stream of content components
    • setContent

      public void setContent(Component... content)
      Sets the content of the fieldset and removes previously set content. Note: Do not include Legend in the content components. Use other FieldSet methods for setting Legend instead.
      Parameters:
      content - the content components of the fieldset to set.