com.vaadin.flow.component.radiobutton.
Class RadioButtonGroup<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<C,T>
-
- com.vaadin.flow.component.AbstractSinglePropertyField<R,T>
-
- com.vaadin.flow.component.radiobutton.GeneratedVaadinRadioGroup<RadioButtonGroup<T>,T>
-
- com.vaadin.flow.component.radiobutton.RadioButtonGroup<T>
-
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasHelper, HasSize, HasStyle, HasTheme, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>, HasItemComponents<T>, HasDataView<T,Void,RadioButtonGroupDataView<T>>, HasListDataView<T,RadioButtonGroupListDataView<T>>, SingleSelect<RadioButtonGroup<T>,T>, Serializable
@NpmPackage(value="@vaadin/vaadin-radio-button", version="22.0.0-alpha5") public class RadioButtonGroup<T> extends GeneratedVaadinRadioGroup<RadioButtonGroup<T>,T> implements HasItemComponents<T>, SingleSelect<RadioButtonGroup<T>,T>, HasListDataView<T,RadioButtonGroupListDataView<T>>, HasDataView<T,Void,RadioButtonGroupDataView<T>>, HasValidation, HasHelper, HasSize
A single select component using radio buttons as options.
This is a server side Java integration for the
vaadin-radio-group
element.Usage examples, see the demo in vaadin.com.
Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.radiobutton.GeneratedVaadinRadioGroup
GeneratedVaadinRadioGroup.InvalidChangeEvent<R extends GeneratedVaadinRadioGroup<R,?>>
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,V>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents
HasItemComponents.ItemComponent<T>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor and Description RadioButtonGroup()
-
Method Summary
All Methods Modifier and Type Method and Description DataProvider<T,?>
getDataProvider()
Deprecated.
usegetListDataView()
orgetGenericDataView()
insteadString
getErrorMessage()
Gets the current error message from the radio button group.
RadioButtonGroupDataView<T>
getGenericDataView()
Gets the generic data view for the RadioButtonGroup.
SerializablePredicate<T>
getItemEnabledProvider()
Returns the item enabled predicate.
ComponentRenderer<? extends 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()
Checks whether the element property has a value that can be converted to the model type.
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()
Specifies that the user must select a value
protected void
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
protected void
onDetach(DetachEvent detachEvent)
Called when the component is detached from a UI.
void
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
void
setDataProvider(DataProvider<T,?> dataProvider)
Deprecated.
use instead one of thesetItems
methods which provide access to eitherRadioButtonGroupListDataView
orRadioButtonGroupDataView
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 radio button group.
RadioButtonGroupDataView<T>
setItems(DataProvider<T,Void> dataProvider)
Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.RadioButtonGroupDataView<T>
setItems(InMemoryDataProvider<T> inMemoryDataProvider)
Sets an in-memory data provider for the component to use
RadioButtonGroupListDataView<T>
setItems(ListDataProvider<T> dataProvider)
Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.void
setItems(Stream<T> streamOfItems)
Deprecated.
Because the stream is collected to a list anyway, useHasListDataView.setItems(Collection)
instead.void
setLabel(String label)
Description copied from corresponding location in WebComponent:
void
setReadOnly(boolean readOnly)
Sets the read-only mode of this
HasValue
to given mode.void
setRenderer(ComponentRenderer<? extends 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)
Sets the value of this object.
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.radiobutton.GeneratedVaadinRadioGroup
addInvalidChangeListener, addThemeVariants, checkValidity, getErrorMessageString, getLabelString, isDisabledBoolean, isInvalidBoolean, isReadonlyBoolean, isRequiredBoolean, removeThemeVariants, setDisabled, setReadonly, validate
-
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, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.data.binder.HasItemComponents
addComponents, getItemPosition, prependComponents
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isRequiredIndicatorVisible, setRequiredIndicatorVisible
-
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, setItems
-
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getCssSize, 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.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Method Detail
-
setItems
public RadioButtonGroupDataView<T> setItems(DataProvider<T,Void> dataProvider)
Description copied from interface:
HasDataView
Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.This method should be used only when the data provider type is not either
ListDataProvider
orBackEndDataProvider
.Specified by:
setItems
in interfaceHasDataView<T,Void,RadioButtonGroupDataView<T>>
Parameters:
dataProvider
- DataProvider instance to use, notnull
Returns:
DataView providing information on the data
-
setItems
public RadioButtonGroupDataView<T> setItems(InMemoryDataProvider<T> inMemoryDataProvider)
Description copied from interface:
HasDataView
Sets an in-memory data provider for the component to use
Note! Using a
ListDataProvider
instead of aInMemoryDataProvider
is recommended to get access toListDataView
API by usingHasListDataView.setItems(ListDataProvider)
.Specified by:
setItems
in interfaceHasDataView<T,Void,RadioButtonGroupDataView<T>>
Parameters:
inMemoryDataProvider
- InMemoryDataProvider to use, notnull
Returns:
DataView providing information on the data
-
setItems
public RadioButtonGroupListDataView<T> setItems(ListDataProvider<T> dataProvider)
Description copied from interface:
HasListDataView
Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.Specified by:
setItems
in interfaceHasListDataView<T,RadioButtonGroupListDataView<T>>
Parameters:
dataProvider
- ListDataProvider providing items to the component.Returns:
ListDataView providing access to the items
-
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 interfaceHasListDataView<T,RadioButtonGroupListDataView<T>>
Returns:
the list data view that provides access to the data bound to the RadioButtonGroup
-
getGenericDataView
public RadioButtonGroupDataView<T> getGenericDataView()
Gets the generic data view for the RadioButtonGroup. This data view should only be used when
getListDataView()
is not applicable for the underlying data provider.Specified by:
getGenericDataView
in interfaceHasDataView<T,Void,RadioButtonGroupDataView<T>>
Returns:
the generic DataView instance implementing
RadioButtonGroupDataView
-
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 returntrue
.Overrides:
hasValidValue
in classAbstractSinglePropertyField<RadioButtonGroup<T>,T>
Returns:
true
if the element property value can be converted to the model type; otherwisefalse
-
setDataProvider
@Deprecated public void setDataProvider(DataProvider<T,?> dataProvider)
Deprecated. use instead one of the
setItems
methods which provide access to eitherRadioButtonGroupListDataView
orRadioButtonGroupDataView
-
setValue
public void setValue(T value)
Description copied from interface:
HasValue
Sets the value of this object. If the new value is not equal to
getValue()
, fires a value change event. May throwIllegalArgumentException
if the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not, and override
HasValue.getEmptyValue()
if the empty value is notnull
.Specified by:
setValue
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>
Overrides:
setValue
in classAbstractField<RadioButtonGroup<T>,T>
Parameters:
value
- the new value
-
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.
-
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.
-
getDataProvider
@Deprecated public DataProvider<T,?> getDataProvider()
Deprecated. use
getListDataView()
orgetGenericDataView()
insteadGets the data provider.
Returns:
the data provider, not
null
-
getItemEnabledProvider
public SerializablePredicate<T> getItemEnabledProvider()
Returns the item enabled predicate.
Returns:
the item enabled predicate
See Also:
setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T>)
-
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, notnull
-
getItemRenderer
public ComponentRenderer<? extends Component,T> getItemRenderer()
Returns the item component renderer.
Returns:
the item renderer
See Also:
-
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, notnull
-
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 classComponent
Parameters:
enabled
- the new enabled state of the component
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:
HasValue
Sets the read-only mode of this
HasValue
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.Specified by:
setReadOnly
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>
Specified by:
setReadOnly
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>
Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:
HasValue
Returns whether this
HasValue
is in read-only mode or not.Specified by:
isReadOnly
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>
Specified by:
isReadOnly
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<RadioButtonGroup<T>,T>,T>
Returns:
false
if the user can modify the value,true
if not.
-
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 classGeneratedVaadinRadioGroup<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 interfaceHasValidation
Overrides:
setErrorMessage
in classGeneratedVaadinRadioGroup<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 interfaceHasValidation
Returns:
the current error message
-
setLabel
public void setLabel(String label)
Description copied from class:
GeneratedVaadinRadioGroup
Description copied from corresponding location in WebComponent:
String used for the label element.
Overrides:
setLabel
in classGeneratedVaadinRadioGroup<RadioButtonGroup<T>,T>
Parameters:
label
- the String value to set
-
getLabel
public String getLabel()
String used for the label element.
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 interfaceHasValidation
Returns:
whether the component input is valid
-
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 interfaceHasValidation
Overrides:
setInvalid
in classGeneratedVaadinRadioGroup<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)
orAbstractField.setModelValue(Object, boolean)
is called. Subclasses can override this method to define an alternative comparison method instead ofObject.equals(Object)
.Overrides:
valueEquals
in classAbstractField<RadioButtonGroup<T>,T>
Parameters:
value1
- the first instancevalue2
- the second instanceReturns:
true
if the instances are equal; otherwisefalse
-
-