public class CheckboxGroup<T> extends GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>> implements HasItemsAndComponents<T>, HasSize, HasValidation, MultiSelect<CheckboxGroup<T>,T>, HasDataProvider<T>, HasHelper, HasLabel, HasValidator<Set<T>>, HasClientValidation
vaadin-checkbox-group element.
CheckBoxGroup is a multiselection component where items are displayed as check boxes.
GeneratedVaadinCheckboxGroup.InvalidChangeEvent<R extends GeneratedVaadinCheckboxGroup<R,?>>AbstractField.ComponentValueChangeEvent<C extends Component,V>HasItemsAndComponents.ItemComponent<T>HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>HasClientValidation.ClientValidatedEvent| Constructor and Description |
|---|
CheckboxGroup() |
| Modifier and Type | Method and Description |
|---|---|
Registration |
addSelectionListener(MultiSelectionListener<CheckboxGroup<T>,T> listener)
Adds a selection listener that will be called when the selection is
changed either by the user or programmatically.
|
Registration |
addValidationStatusChangeListener(ValidationStatusChangeListener<Set<T>> listener)
Enables the implementing components to notify changes in their validation
status to the observers.
|
DataProvider<T,?> |
getDataProvider()
Gets the data provider.
|
String |
getErrorMessage()
Gets the current error message from the checkbox group.
|
SerializablePredicate<T> |
getItemEnabledProvider()
Returns the item enabled predicate.
|
ItemLabelGenerator<T> |
getItemLabelGenerator()
Gets the item label generator that is used to produce the strings shown
in the checkbox group for each item.
|
String |
getLabel()
Gets the label of the checkbox group.
|
Set<T> |
getSelectedItems()
Returns an immutable set of the currently selected items.
|
protected boolean |
hasValidValue()
Checks whether the element property has a value that can be converted to
the model type.
|
protected boolean |
isEnforcedFieldValidationEnabled() |
boolean |
isInvalid()
Returns
true if component input is invalid, false
otherwise. |
boolean |
isReadOnly()
Returns whether this
HasValue is in read-only mode or not. |
boolean |
isRequired()
Determines whether the checkbox group is marked as input required.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
|
void |
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
|
void |
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
|
void |
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
|
void |
setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)
Sets the item enabled predicate for this checkbox group.
|
void |
setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator that is used to produce the strings shown
in the checkbox group for each item.
|
void |
setLabel(String label)
Sets the label for the checkbox group.
|
void |
setReadOnly(boolean readOnly)
Sets the read-only mode of this
HasValue to given mode. |
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)
Updates the selection by adding and removing the given items from it.
|
protected void |
validate()
Description copied from corresponding location in WebComponent:
|
protected boolean |
valueEquals(Set<T> value1,
Set<T> value2)
Compares to value instances to each other to determine whether they are
equal.
|
addInvalidChangeListener, addThemeVariants, getErrorMessageString, getLabelString, isDisabledBoolean, isInvalidBoolean, isRequiredBoolean, removeThemeVariants, setDisabledgetSynchronizationRegistration, setPresentationValue, setSynchronizedEventaddValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValueaddListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddComponents, getItemPosition, prependComponentsadd, add, addComponentAsFirst, addComponentAtIndex, remove, removeAllgetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFulldeselect, deselect, deselectAll, getEmptyValue, getValue, isSelected, select, selectisRequiredIndicatorVisible, setRequiredIndicatorVisibleaddValueChangeListener, clear, getOptionalValue, isEmptyisEnabled, setEnabledsetItemsgetHelperComponent, getHelperText, setHelperComponent, setHelperTextgetDefaultValidatoraddClientValidatedEventListeneraddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameaddThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameaddAttachListeneraddDetachListenerprotected void onAttach(AttachEvent attachEvent)
ComponentThe default implementation does nothing.
This method is invoked before the AttachEvent is fired for the
component.
public void setDataProvider(DataProvider<T,?> dataProvider)
HasDataProvidersetDataProvider in interface HasDataProvider<T>dataProvider - the data provider, not nullpublic void updateSelection(Set<T> addedItems, Set<T> removedItems)
MultiSelectIf all the added items were already selected and the removed items were not selected, this is a NO-OP.
Duplicate items (in both add and remove sets) are ignored.
updateSelection in interface MultiSelect<CheckboxGroup<T>,T>addedItems - the items to add, not nullremovedItems - the items to remove, not nullpublic void setValue(Set<T> value)
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.
setValue in interface HasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>setValue in interface MultiSelect<CheckboxGroup<T>,T>setValue in class AbstractField<CheckboxGroup<T>,Set<T>>value - the new value to set, not nullNullPointerException - if value is nullpublic Set<T> getSelectedItems()
MultiSelectSelectionModel methods while iterating over the set.
Implementation note: the iteration order of the items in the returned set should be well-defined and documented by the implementing class.
getSelectedItems in interface MultiSelect<CheckboxGroup<T>,T>nullpublic Registration addSelectionListener(MultiSelectionListener<CheckboxGroup<T>,T> listener)
MultiSelectaddSelectionListener in interface MultiSelect<CheckboxGroup<T>,T>listener - the value change listener, not nullpublic DataProvider<T,?> getDataProvider()
nullpublic void onEnabledStateChanged(boolean enabled)
ComponentBy default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
onEnabledStateChanged in class Componentenabled - the new enabled state of the componentpublic void setReadOnly(boolean readOnly)
HasValueHasValue to given mode. The user
can't change the value when in read-only mode.
A HasValue with a visual component in read-only mode typically
looks visually different to signal to the user that the value cannot be
edited.
setReadOnly in interface HasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>setReadOnly in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>readOnly - a boolean value specifying whether the component is put
read-only mode or notpublic boolean isReadOnly()
HasValueHasValue is in read-only mode or not.isReadOnly in interface HasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>isReadOnly in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>false if the user can modify the value, true if
not.public SerializablePredicate<T> getItemEnabledProvider()
setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T>)public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)
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).itemEnabledProvider - the item enable predicate, not nullpublic void setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
String.valueOf(Object) is used.itemLabelGenerator - the item label provider to use, not nullpublic ItemLabelGenerator<T> getItemLabelGenerator()
public void setLabel(String label)
setLabel in interface HasLabelsetLabel in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>label - value for the label property in the checkbox grouppublic String getLabel()
public void setErrorMessage(String errorMessage)
GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
Error to show when the input value is invalid.
setErrorMessage in interface HasValidationsetErrorMessage in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>errorMessage - the String value to setpublic String getErrorMessage()
getErrorMessage in interface HasValidationpublic void setRequired(boolean required)
GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
Specifies that the user must fill in a value.
setRequired in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>required - the boolean value to setpublic boolean isRequired()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
true if the input is required, false otherwisepublic boolean isInvalid()
HasValidationtrue if component input is invalid, false
otherwise.isInvalid in interface HasValidationpublic void setInvalid(boolean invalid)
GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
This property is set to true when the control value is invalid.
setInvalid in interface HasValidationsetInvalid in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>invalid - the boolean value to setprotected boolean valueEquals(Set<T> value1, Set<T> value2)
AbstractFieldAbstractField.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).valueEquals in class AbstractField<CheckboxGroup<T>,Set<T>>value1 - the first instancevalue2 - the second instancetrue if the instances are equal; otherwise
falseprotected boolean hasValidValue()
AbstractSinglePropertyFieldfalse. The default implementation always
return true.hasValidValue in class AbstractSinglePropertyField<CheckboxGroup<T>,Set<T>>true if the element property value can be converted
to the model type; otherwise falseprotected void validate()
GeneratedVaadinCheckboxGroupDescription 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.
validate in class GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<Set<T>> listener)
HasValidator
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));
}
}
}
addValidationStatusChangeListener in interface HasValidator<Set<T>>Binder.BindingBuilderImpl.bind(ValueProvider,
Setter)protected boolean isEnforcedFieldValidationEnabled()
Copyright © 2025. All rights reserved.