Class RadioButtonGroup<T>

  • All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>, HasTooltip, com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.data.binder.HasValidator<T>, com.vaadin.flow.data.provider.HasDataView<T,​Void,​RadioButtonGroupDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,​RadioButtonGroupListDataView<T>>, com.vaadin.flow.data.selection.SingleSelect<RadioButtonGroup<T>,​T>, Serializable

    @NpmPackage(value="@vaadin/radio-group",version="23.6.1") @NpmPackage(value="@vaadin/vaadin-radio-button",version="23.6.1")
    public class RadioButtonGroup<T>
    extends GeneratedVaadinRadioGroup<RadioButtonGroup<T>,​T>
    implements com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.data.selection.SingleSelect<RadioButtonGroup<T>,​T>, com.vaadin.flow.data.provider.HasListDataView<T,​RadioButtonGroupListDataView<T>>, com.vaadin.flow.data.provider.HasDataView<T,​Void,​RadioButtonGroupDataView<T>>, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasLabel, HasTooltip, com.vaadin.flow.data.binder.HasValidator<T>
    Radio Button Group allows the user to select exactly one value from a list of related but mutually exclusive options.
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

        com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,​V extends Object>
      • Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents

        com.vaadin.flow.data.binder.HasItemComponents.ItemComponent<T extends Object>
      • Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

        com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
    • Constructor Summary

      Constructors 
      Constructor Description
      RadioButtonGroup()
      Default constructor.
      RadioButtonGroup​(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener)
      Constructs a radio button group with a value change listener.
      RadioButtonGroup​(String label)
      Creates an empty radio button group with the defined label.
      RadioButtonGroup​(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener)
      Constructs a radio button group with the defined label and a value change listener.
      RadioButtonGroup​(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener, T... items)
      Constructs a radio button group with the defined label, a value change listener and populated with the items in the array.
      RadioButtonGroup​(String label, Collection<T> items)
      Creates a radio button group with the defined label and populated with the items in the collection.
      RadioButtonGroup​(String label, T... items)
      Creates a radio button group with the defined label and populated with the items in the array.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void add​(com.vaadin.flow.component.Component... components)
      Deprecated.
      since v23.3.
      void add​(String text)
      Deprecated.
      since v23.3.
      void add​(Collection<com.vaadin.flow.component.Component> components)
      Deprecated.
      since v23.3.
      void addComponentAsFirst​(com.vaadin.flow.component.Component component)
      Deprecated.
      since v23.3.
      void addComponentAtIndex​(int index, com.vaadin.flow.component.Component component)
      Deprecated.
      since v23.3.
      void addComponents​(T afterItem, com.vaadin.flow.component.Component... components)
      Deprecated.
      since v23.3.
      void addThemeVariants​(RadioGroupVariant... variants)
      Adds theme variants to the component.
      com.vaadin.flow.data.provider.DataProvider<T,​?> getDataProvider()
      Deprecated.
      String getErrorMessage()
      Gets the current error message from the radio button group.
      RadioButtonGroupDataView<T> getGenericDataView()
      Gets the generic data view for the RadioButtonGroup.
      com.vaadin.flow.function.SerializablePredicate<T> getItemEnabledProvider()
      Returns the item enabled predicate.
      com.vaadin.flow.component.ItemLabelGenerator<T> getItemLabelGenerator()
      Gets the item label generator that is used to produce the strings shown in the radio button group for each item.
      int getItemPosition​(T item)
      Deprecated.
      since v23.3.
      ComponentRenderer<? extends com.vaadin.flow.component.Component,​T> getItemRenderer()
      Returns the item component renderer.
      String getLabel()
      String used for the label element.
      RadioButtonGroupListDataView<T> getListDataView()
      Gets the list data view for the RadioButtonGroup.
      protected boolean hasValidValue()  
      boolean isInvalid()  
      boolean isReadOnly()  
      boolean isRequired()
      Specifies that the user must select a value
      protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)  
      protected void onDetach​(com.vaadin.flow.component.DetachEvent detachEvent)  
      void onEnabledStateChanged​(boolean enabled)  
      void prependComponents​(T beforeItem, com.vaadin.flow.component.Component... components)
      Deprecated.
      since v23.3.
      void remove​(com.vaadin.flow.component.Component... components)
      Deprecated.
      since v23.3.
      void remove​(Collection<com.vaadin.flow.component.Component> components)
      Deprecated.
      since v23.3.
      void removeAll()
      Deprecated.
      since v23.3.
      void removeThemeVariants​(RadioGroupVariant... variants)
      Removes theme variants from the component.
      void setDataProvider​(com.vaadin.flow.data.provider.DataProvider<T,​?> dataProvider)
      Deprecated.
      use instead one of the setItems methods which provide access to either RadioButtonGroupListDataView or RadioButtonGroupDataView
      void setErrorMessage​(String errorMessage)
      Description copied from corresponding location in WebComponent:
      void setInvalid​(boolean invalid)
      Description copied from corresponding location in WebComponent:
      void setItemEnabledProvider​(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
      Sets the item enabled predicate for this radio button group.
      void setItemLabelGenerator​(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
      Sets the item label generator that is used to produce the strings shown in the radio button group for each item.
      RadioButtonGroupDataView<T> setItems​(com.vaadin.flow.data.provider.DataProvider<T,​Void> dataProvider)  
      RadioButtonGroupDataView<T> setItems​(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider)  
      RadioButtonGroupListDataView<T> setItems​(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider)  
      void setItems​(Stream<T> streamOfItems)
      Deprecated.
      Because the stream is collected to a list anyway, use HasListDataView.setItems(Collection) instead.
      void setLabel​(String label)
      Sets the label for the field.
      void setReadOnly​(boolean readOnly)  
      void setRenderer​(ComponentRenderer<? extends com.vaadin.flow.component.Component,​T> renderer)
      Sets the item renderer for this radio button group.
      void setRequired​(boolean required)
      Specifies that the user must select in a value.
      void setValue​(T value)  
      protected boolean valueEquals​(T value1, T value2)
      Compares two value instances to each other to determine whether they are equal.
      • Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

        getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent
      • Methods inherited from class com.vaadin.flow.component.AbstractField

        addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue
      • 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, scrollIntoView, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.AttachNotifier

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

        addDetachListener
      • 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.HasHelper

        getHelperComponent, getHelperText, setHelperComponent, setHelperText
      • Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView

        setItems, setItems
      • 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.HasTheme

        addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
      • Methods inherited from interface com.vaadin.flow.data.binder.HasValidator

        addValidationStatusChangeListener, getDefaultValidator
      • Methods inherited from interface com.vaadin.flow.component.HasValue

        addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty
      • Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

        isRequiredIndicatorVisible, setRequiredIndicatorVisible
    • Constructor Detail

      • RadioButtonGroup

        public RadioButtonGroup()
        Default constructor. Creates an empty radio button group.
      • RadioButtonGroup

        public RadioButtonGroup​(String label)
        Creates an empty radio button group with the defined label.
        Parameters:
        label - the label describing the radio button group
        See Also:
        setLabel(String)
      • RadioButtonGroup

        public RadioButtonGroup​(String label,
                                Collection<T> items)
        Creates a radio button group with the defined label and populated with the items in the collection.
        Parameters:
        label - the label describing the radio button group
        items - the items to be shown in the list of the radio button group
        See Also:
        setLabel(String), HasListDataView.setItems(Collection)
      • RadioButtonGroup

        @SafeVarargs
        public RadioButtonGroup​(String label,
                                T... items)
        Creates a radio button group with the defined label and populated with the items in the array.
        Parameters:
        label - the label describing the radio button group
        items - the items to be shown in the list of the radio button group
        See Also:
        setLabel(String), HasListDataView.setItems(Object...)
      • RadioButtonGroup

        public RadioButtonGroup​(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener)
        Constructs a radio button group with a value change listener.
        Parameters:
        listener - the value change listener to add
        See Also:
        AbstractField.addValueChangeListener(ValueChangeListener)
      • RadioButtonGroup

        public RadioButtonGroup​(String label,
                                com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener)
        Constructs a radio button group with the defined label and a value change listener.
        Parameters:
        label - the label describing the radio button group
        listener - the value change listener to add
        See Also:
        setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener)
      • RadioButtonGroup

        @SafeVarargs
        public RadioButtonGroup​(String label,
                                com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>> listener,
                                T... items)
        Constructs a radio button group with the defined label, a value change listener and populated with the items in the array.
        Parameters:
        label - the label describing the radio button group
        listener - the value change listener to add
        items - the items to be shown in the list of the radio button group
        See Also:
        setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener), HasListDataView.setItems(Object...)
    • Method Detail

      • setItems

        @Deprecated
        public void setItems​(Stream<T> streamOfItems)
        Deprecated.
        Because the stream is collected to a list anyway, use HasListDataView.setItems(Collection) instead.
      • getListDataView

        public RadioButtonGroupListDataView<T> getListDataView()
        Gets the list data view for the RadioButtonGroup. This data view should only be used when the items are in-memory and set with: If the items are not in-memory an exception is thrown.
        Specified by:
        getListDataView in interface com.vaadin.flow.data.provider.HasListDataView<T,​RadioButtonGroupListDataView<T>>
        Returns:
        the list data view that provides access to the data bound to the RadioButtonGroup
      • hasValidValue

        protected boolean hasValidValue()
        Overrides:
        hasValidValue in class com.vaadin.flow.component.AbstractSinglePropertyField<RadioButtonGroup<T>,​T>
      • setItemLabelGenerator

        public void setItemLabelGenerator​(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
        Sets the item label generator that is used to produce the strings shown in the radio button group for each item. By default, String.valueOf(Object) is used.

        Parameters:
        itemLabelGenerator - the item label provider to use, not null
      • getItemLabelGenerator

        public com.vaadin.flow.component.ItemLabelGenerator<T> getItemLabelGenerator()
        Gets the item label generator that is used to produce the strings shown in the radio button group for each item.
        Returns:
        the item label generator used, not null
      • setValue

        public void setValue​(T value)
        Specified by:
        setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>
        Overrides:
        setValue in class com.vaadin.flow.component.AbstractField<RadioButtonGroup<T>,​T>
      • onAttach

        protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)
        Overrides:
        onAttach in class com.vaadin.flow.component.Component
      • onDetach

        protected void onDetach​(com.vaadin.flow.component.DetachEvent detachEvent)
        Overrides:
        onDetach in class com.vaadin.flow.component.Component
      • setItemEnabledProvider

        public void setItemEnabledProvider​(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
        Sets the item enabled predicate for this radio button group. The predicate is applied to each item to determine whether the item should be enabled (true) or disabled (false). Disabled items are displayed as grayed out and the user cannot select them. The default predicate always returns true (all the items are enabled).
        Parameters:
        itemEnabledProvider - the item enable predicate, not null
      • setRenderer

        public void setRenderer​(ComponentRenderer<? extends com.vaadin.flow.component.Component,​T> renderer)
        Sets the item renderer for this radio button group. The renderer is applied to each item to create a component which represents the item.

        Note: Component acts as a label to the button and clicks on it trigger the radio button. Hence interactive components like DatePicker or ComboBox cannot be used.

        Parameters:
        renderer - the item renderer, not null
      • onEnabledStateChanged

        public void onEnabledStateChanged​(boolean enabled)
        Overrides:
        onEnabledStateChanged in class com.vaadin.flow.component.Component
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
        Specified by:
        setReadOnly in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>
        Specified by:
        setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>
      • isReadOnly

        public boolean isReadOnly()
        Specified by:
        isReadOnly in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>
        Specified by:
        isReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,​T>,​T>
      • setRequired

        public void setRequired​(boolean required)
        Specifies that the user must select in a value.

        NOTE: The required indicator will not be visible, if there is no label property set for the RadioButtonGroup.

        Overrides:
        setRequired in class GeneratedVaadinRadioGroup<RadioButtonGroup<T>,​T>
        Parameters:
        required - the boolean value to set
      • isRequired

        public boolean isRequired()
        Specifies that the user must select a value

        This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.

        Returns:
        the required property from the webcomponent
      • setErrorMessage

        public void setErrorMessage​(String errorMessage)
        Description copied from class: GeneratedVaadinRadioGroup

        Description copied from corresponding location in WebComponent:

        Error to show when the input value is invalid.

        Specified by:
        setErrorMessage in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setErrorMessage in class GeneratedVaadinRadioGroup<RadioButtonGroup<T>,​T>
        Parameters:
        errorMessage - the String value to set
      • getErrorMessage

        public String getErrorMessage()
        Gets the current error message from the radio button group.
        Specified by:
        getErrorMessage in interface com.vaadin.flow.component.HasValidation
        Returns:
        the current error message
      • setLabel

        public void setLabel​(String label)
        Sets the label for the field.
        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Overrides:
        setLabel in class GeneratedVaadinRadioGroup<RadioButtonGroup<T>,​T>
        Parameters:
        label - value for the label property in the webcomponent
      • getLabel

        public String getLabel()
        String used for the label element.
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Returns:
        the label property from the webcomponent
      • isInvalid

        public boolean isInvalid()
        Specified by:
        isInvalid in interface com.vaadin.flow.component.HasValidation
      • setInvalid

        public void setInvalid​(boolean invalid)
        Description copied from class: GeneratedVaadinRadioGroup

        Description copied from corresponding location in WebComponent:

        This property is set to true when the value is invalid.

        Specified by:
        setInvalid in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setInvalid in class GeneratedVaadinRadioGroup<RadioButtonGroup<T>,​T>
        Parameters:
        invalid - the boolean value to set
      • valueEquals

        protected boolean valueEquals​(T value1,
                                      T value2)
        Compares two value instances to each other to determine whether they are equal. Equality is used to determine whether to update internal state and fire an event when setValue(Object) or AbstractField.setModelValue(Object, boolean) is called. Subclasses can override this method to define an alternative comparison method instead of Object.equals(Object).
        Overrides:
        valueEquals in class com.vaadin.flow.component.AbstractField<RadioButtonGroup<T>,​T>
        Parameters:
        value1 - the first instance
        value2 - the second instance
        Returns:
        true if the instances are equal; otherwise false
      • add

        @Deprecated
        public void add​(com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        add in interface com.vaadin.flow.component.HasComponents
      • add

        @Deprecated
        public void add​(Collection<com.vaadin.flow.component.Component> components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        add in interface com.vaadin.flow.component.HasComponents
      • add

        @Deprecated
        public void add​(String text)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        add in interface com.vaadin.flow.component.HasComponents
      • remove

        @Deprecated
        public void remove​(com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        remove in interface com.vaadin.flow.component.HasComponents
      • remove

        @Deprecated
        public void remove​(Collection<com.vaadin.flow.component.Component> components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        remove in interface com.vaadin.flow.component.HasComponents
      • removeAll

        @Deprecated
        public void removeAll()
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        removeAll in interface com.vaadin.flow.component.HasComponents
      • addComponentAtIndex

        @Deprecated
        public void addComponentAtIndex​(int index,
                                        com.vaadin.flow.component.Component component)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        addComponentAtIndex in interface com.vaadin.flow.component.HasComponents
      • addComponentAsFirst

        @Deprecated
        public void addComponentAsFirst​(com.vaadin.flow.component.Component component)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        addComponentAsFirst in interface com.vaadin.flow.component.HasComponents
      • addComponents

        @Deprecated
        public void addComponents​(T afterItem,
                                  com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        addComponents in interface com.vaadin.flow.data.binder.HasItemComponents<T>
      • prependComponents

        @Deprecated
        public void prependComponents​(T beforeItem,
                                      com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        prependComponents in interface com.vaadin.flow.data.binder.HasItemComponents<T>
      • getItemPosition

        @Deprecated
        public int getItemPosition​(T item)
        Deprecated.
        since v23.3. This component is not intended to be used as a generic component container, and its implementation of HasComponents and HasItemComponents will be removed in v24.
        Specified by:
        getItemPosition in interface com.vaadin.flow.data.binder.HasItemComponents<T>