com.vaadin.flow.component.radiobutton.

Class RadioButtonGroup<T>

    • Constructor Detail

      • RadioButtonGroup

        public RadioButtonGroup()
    • Method Detail

      • hasValidValue

        protected boolean hasValidValue()

        Description copied from class: AbstractSinglePropertyField

        Checks whether the element property has a value that can be converted to the model type. Property changes from the element will be ignored if this method returns false. The default implementation always return true.

        Overrides:

        hasValidValue in class AbstractSinglePropertyField<RadioButtonGroup<T>,T>

        Returns:

        true if the element property value can be converted to the model type; otherwise false

      • setDataProvider

        public void setDataProvider(DataProvider<T,?> dataProvider)

        Description copied from interface: HasDataProvider

        Sets the data provider for this listing. The data provider is queried for displayed items as needed.

        Specified by:

        setDataProvider in interface HasDataProvider<T>

        Parameters:

        dataProvider - the data provider, not null

      • onAttach

        protected void onAttach(AttachEvent attachEvent)

        Description copied from class: Component

        Called when the component is attached to a UI.

        The default implementation does nothing.

        This method is invoked before the AttachEvent is fired for the component.

        Overrides:

        onAttach in class Component

        Parameters:

        attachEvent - the attach event

      • onDetach

        protected void onDetach(DetachEvent detachEvent)

        Description copied from class: Component

        Called when the component is detached from a UI.

        The default implementation does nothing.

        This method is invoked before the DetachEvent is fired for the component.

        Overrides:

        onDetach in class Component

        Parameters:

        detachEvent - the detach event

      • getDataProvider

        public DataProvider<T,?> getDataProvider()

        Gets the data provider.

        Returns:

        the data provider, not null

      • setItemEnabledProvider

        public void setItemEnabledProvider(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 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)

        Description copied from class: Component

        Handle component enable state when the enabled state changes.

        By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.

        Overrides:

        onEnabledStateChanged in class Component

        Parameters:

        enabled - the new enabled state of the component

      • 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 radiobutton group.

        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

      • getErrorMessage

        public String getErrorMessage()

        Gets the current error message from the radio button group.

        Specified by:

        getErrorMessage in interface HasValidation

        Returns:

        the current error message

      • getLabel

        public String getLabel()

        String used for the label element.

        Specified by:

        getLabel in interface HasLabel

        Returns:

        the label property from the webcomponent

      • isInvalid

        public boolean isInvalid()

        Description copied from interface: HasValidation

        Returns true if component input is invalid, false otherwise.

        Specified by:

        isInvalid in interface HasValidation

        Returns:

        whether the component input is valid

      • validate

        protected void validate()

        Description copied from class: GeneratedVaadinRadioGroup

        Description copied from corresponding location in WebComponent:

        Returns true if value is valid. <iron-form> uses this to check the validity or all its elements.

        This function is not supported by Flow because it returns a boolean. Functions with return types different than void are not supported at this moment.

        Overrides:

        validate in class GeneratedVaadinRadioGroup<RadioButtonGroup<T>,T>

      • addValidationStatusChangeListener

        public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<T> listener)

        Description copied from interface: HasValidator

        Enables the implementing components to notify changes in their validation status to the observers.

        Note: This method can be overridden by the implementing classes e.g. components, to enable the associated Binder.Binding instance subscribing for their validation change events and revalidate itself.

        This method primarily designed for notifying the Binding about the validation status changes of a bound component at the client-side. WebComponents such as <vaadin-date-picker> or any other component that accept a formatted text as input should be able to communicate their invalid status to their server-side instance, and a bound server-side component instance must notify its binding about this validation status change as well. When the binding instance revalidates, a chain of validators and convertors get executed one of which is the default validator provided by HasValidator.getDefaultValidator(). Thus, In order for the binding to be able to show/clear errors for its associated bound field, it is important that implementing components take that validation status into account while implementing any validator and converter including HasValidator.getDefaultValidator(). Here is an example:

         @Tag("date-picker-demo")
         public class DatePickerDemo implements HasValidator<LocalDate> {
        
             // Each web component has a way to communicate its validation status
             // to its server-side component instance. The following clientSideValid
             // state is introduced here just for the sake of simplicity of this code
             // snippet:
             boolean clientSideValid = true;
        
             /**
              * Note how clientSideValid engaged in the definition
              * of this method. It is important to reflect this status either
              * in the returning validation result of this method or any other
              * validation that is associated with this component.
              */
             @Override
             public Validator getDefaultValidator() {
                  return (value, valueContext) -> clientSideValid ? ValidationResult.ok()
                         : ValidationResult.error("Invalid date format");
             }
        
             private final Collection<ValidationStatusChangeListener<LocalDate>>
                 validationStatusListeners = new ArrayList<>();
        
             /**
              * This enables the binding to subscribe for the validation status
              * change events that are fired by this component and revalidate
              * itself respectively.
              */
             @Override
             public Registration addValidationStatusChangeListener(
                     ValidationStatusChangeListener<LocalDate> listener) {
                 validationStatusListeners.add(listener);
                 return () -> validationStatusListeners.remove(listener);
             }
        
             private void fireValidationStatusChangeEvent(
                     boolean newValidationStatus) {
                 if (this.clientSideValid != newValidationStatus) {
                     this.clientSideValid = newValidationStatus;
                     var event = new ValidationStatusChangeEvent<>(this,
                             newValidationStatus);
                     validationStatusListeners.forEach(
                             listener -> listener.validationStatusChanged(event));
                 }
             }
         }
         

        Specified by:

        addValidationStatusChangeListener in interface HasValidator<T>

        Returns:

        Registration of the added listener.

        See Also:

        Binder.BindingBuilderImpl.bind(ValueProvider, Setter)

      • isEnforcedFieldValidationEnabled

        protected boolean isEnforcedFieldValidationEnabled()