Class CheckboxGroup<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<CheckboxGroup<T>,​Set<T>>,​Set<T>>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>,​Set<T>>, HasTooltip, com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.data.binder.HasValidator<T>, com.vaadin.flow.data.provider.HasDataView<T,​Void,​CheckboxGroupDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,​CheckboxGroupListDataView<T>>, com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>, Serializable

    public class CheckboxGroup<T>
    extends GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,​Set<T>>
    implements com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>, com.vaadin.flow.data.provider.HasListDataView<T,​CheckboxGroupListDataView<T>>, com.vaadin.flow.data.provider.HasDataView<T,​Void,​CheckboxGroupDataView<T>>, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, HasTooltip, com.vaadin.flow.data.binder.HasValidator<T>
    CheckBoxGroup is a multi-selection component where items are displayed as check boxes.

    Use CheckBoxGroup to group related items. Individual checkboxes should be used for options that are not related to each other in any way.

    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
      CheckboxGroup()
      Creates an empty checkbox group
      CheckboxGroup​(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>> listener)
      Constructs a checkbox group with a value change listener.
      CheckboxGroup​(String label)
      Creates an empty checkbox group with the defined label.
      CheckboxGroup​(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>> listener)
      Constructs a checkbox group with the defined label and a value change listener.
      CheckboxGroup​(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>> listener, T... items)
      Constructs a checkbox group with the defined label, a value change listener and populated with the items in the array.
      CheckboxGroup​(String label, Collection<T> items)
      Creates a checkbox group with the defined label and populated with the items in the collection.
      CheckboxGroup​(String label, T... items)
      Creates a checkbox 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
      com.vaadin.flow.shared.Registration addSelectionListener​(com.vaadin.flow.data.selection.MultiSelectionListener<CheckboxGroup<T>,​T> listener)  
      void addThemeVariants​(CheckboxGroupVariant... 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 checkbox group.
      CheckboxGroupDataView<T> getGenericDataView()
      Gets the generic data view for the checkbox group.
      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 checkbox group for each item.
      ComponentRenderer<? extends com.vaadin.flow.component.Component,​T> getItemRenderer()
      Returns the item component renderer.
      String getLabel()
      Gets the label of the checkbox group.
      CheckboxGroupListDataView<T> getListDataView()
      Gets the list data view for the checkbox group.
      Set<T> getSelectedItems()  
      protected boolean hasValidValue()  
      boolean isInvalid()  
      boolean isReadOnly()  
      boolean isRequired()
      Determines whether the checkbox group is marked as input required.
      protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)  
      void onEnabledStateChanged​(boolean enabled)  
      void removeThemeVariants​(CheckboxGroupVariant... 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 CheckboxGroupListDataView or CheckboxGroupDataView
      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 checkbox 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 checkbox group for each item.
      CheckboxGroupDataView<T> setItems​(com.vaadin.flow.data.provider.DataProvider<T,​Void> dataProvider)  
      CheckboxGroupDataView<T> setItems​(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider)  
      CheckboxGroupListDataView<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 checkbox group.
      void setReadOnly​(boolean readOnly)  
      void setRenderer​(ComponentRenderer<? extends com.vaadin.flow.component.Component,​T> renderer)
      Sets the item renderer for this checkbox group.
      void setRequired​(boolean required)
      Description copied from corresponding location in WebComponent:
      void setValue​(Set<T> value)
      Sets the value of this component.
      void updateSelection​(Set<T> addedItems, Set<T> removedItems)  
      protected boolean valueEquals​(Set<T> value1, Set<T> value2)  
      • 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, onDetach, 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.HasComponents

        add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll
      • 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.binder.HasItemComponents

        addComponents, getItemPosition, prependComponents
      • 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, getOptionalValue, isEmpty
      • Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

        isRequiredIndicatorVisible, setRequiredIndicatorVisible
      • Methods inherited from interface com.vaadin.flow.data.selection.MultiSelect

        deselect, deselect, deselectAll, getEmptyValue, getValue, isSelected, select, select
    • Constructor Detail

      • CheckboxGroup

        public CheckboxGroup()
        Creates an empty checkbox group
      • CheckboxGroup

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

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

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

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

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

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

      • onAttach

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

        public CheckboxGroupDataView<T> setItems​(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider)
        Specified by:
        setItems in interface com.vaadin.flow.data.provider.HasDataView<T,​Void,​CheckboxGroupDataView<T>>
      • getListDataView

        public CheckboxGroupListDataView<T> getListDataView()
        Gets the list data view for the checkbox group. 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,​CheckboxGroupListDataView<T>>
        Returns:
        the list data view that provides access to the data bound to the checkbox group
      • getGenericDataView

        public CheckboxGroupDataView<T> getGenericDataView()
        Gets the generic data view for the checkbox group. This data view should only be used when getListDataView() is not applicable for the underlying data provider.
        Specified by:
        getGenericDataView in interface com.vaadin.flow.data.provider.HasDataView<T,​Void,​CheckboxGroupDataView<T>>
        Returns:
        the generic DataView instance implementing CheckboxGroupDataView
      • setItems

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

        public void updateSelection​(Set<T> addedItems,
                                    Set<T> removedItems)
        Specified by:
        updateSelection in interface com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>
      • setValue

        public void setValue​(Set<T> value)
        Sets the value of this component. If the new value is not equal to the previous value, fires a value change event.

        The component doesn't accept null values. The value of a checkbox group without any selected items is an empty set. You can use the HasValue.clear() method to set the empty value.

        Specified by:
        setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>,​Set<T>>
        Specified by:
        setValue in interface com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>
        Overrides:
        setValue in class com.vaadin.flow.component.AbstractField<CheckboxGroup<T>,​Set<T>>
        Parameters:
        value - the new value to set, not null
        Throws:
        NullPointerException - if value is null
      • getSelectedItems

        public Set<T> getSelectedItems()
        Specified by:
        getSelectedItems in interface com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>
      • addSelectionListener

        public com.vaadin.flow.shared.Registration addSelectionListener​(com.vaadin.flow.data.selection.MultiSelectionListener<CheckboxGroup<T>,​T> listener)
        Specified by:
        addSelectionListener in interface com.vaadin.flow.data.selection.MultiSelect<CheckboxGroup<T>,​T>
      • 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<CheckboxGroup<T>,​Set<T>>,​Set<T>>
        Specified by:
        setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,​Set<T>>,​Set<T>>
      • isReadOnly

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

        public void setItemEnabledProvider​(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
        Sets the item enabled predicate for this checkbox 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
      • 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 checkbox 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 checkbox group for each item.
        Returns:
        the item label generator used, not null
      • setLabel

        public void setLabel​(String label)
        Sets the label for the checkbox group.
        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Overrides:
        setLabel in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,​Set<T>>
        Parameters:
        label - value for the label property in the checkbox group
      • getLabel

        public String getLabel()
        Gets the label of the checkbox group.
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Returns:
        the label property of the checkbox group
      • setErrorMessage

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

        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 GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,​Set<T>>
        Parameters:
        errorMessage - the String value to set
      • getErrorMessage

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

        public boolean isRequired()
        Determines whether the checkbox group is marked as input required.

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

        Returns:
        true if the input is required, false otherwise
      • isInvalid

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

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

        Description copied from corresponding location in WebComponent:

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

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

        protected boolean valueEquals​(Set<T> value1,
                                      Set<T> value2)
        Overrides:
        valueEquals in class com.vaadin.flow.component.AbstractField<CheckboxGroup<T>,​Set<T>>
      • hasValidValue

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

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

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

        Parameters:
        renderer - the item renderer, not null
        Since:
        23.1