checkboxGroup
checkBoxGroup
allows users to select multiple values from a list of items using checkboxes.
-
XML element:
checkBoxGroup
-
Java class:
JmixCheckboxGroup
Basics
The simplest case of using checkBoxGroup
is to select values from an enumeration.
<checkboxGroup itemsEnum="com.company.onboarding.entity.DayOfWeek"
label="Select days of week"
themeNames="vertical"/>
Data Binding
You can bind a component to an entity and its attributes hold in a data container.
To bind checkBoxGroup
to an entity attribute:
-
Specify the name of the data container as the dataContainer attribute value.
-
Specify the name of the entity attribute as the property attribute value.
<data>
<instance class="com.company.onboarding.entity.User" id="userDc">
<fetchPlan extends="_base">
<property name="hobbies" fetchPlan="_base"/>
</fetchPlan>
<loader id="userDl"/>
</instance>
<collection class="com.company.onboarding.entity.Hobby" id="hobbiesDc">
<fetchPlan extends="_base"/>
<loader id="hobbiesDl">
<query>
<![CDATA[select e from Hobby e]]>
</query>
</loader>
</collection>
</data>
<layout>
<checkboxGroup dataContainer="userDc"
property="hobbies"
itemsContainer="hobbiesDc"
id="checkboxGroup"/>
</layout>
In this case, checkBoxGroup
will display instance names of the Hobby
entity, and its getTypedValue()
method will return the Collection
of selected entity instances.
Custom Items
To set the list of checkBoxGroup
items, use the following methods:
-
setItems()
- allows you to specify component items programmatically.@ViewComponent private JmixCheckboxGroup<Integer> checkboxGroupInt; @Subscribe public void onInit(final InitEvent event) { checkboxGroupInt.setItems(new ArrayList<>(Arrays.asList(1,2,3,4,5))); }
-
ComponentUtils.setItemsMap()
- allows you to specify a string label for each item value explicitly.@ViewComponent private JmixCheckboxGroup<Integer> ratingCheckboxGroup; @Subscribe public void onInit(final InitEvent event) { Map<Integer,String> map = new LinkedHashMap<>(); map.put(2,"Poor"); map.put(3,"Average"); map.put(4,"Good"); map.put(5,"Excellent"); ComponentUtils.setItemsMap(ratingCheckboxGroup, map); }
Attributes
id - alignSelf - classNames - colspan - dataContainer - enabled - errorMessage - height - helperText - invalid - itemsContainer - itemsEnum - label - maxHeight - maxWidth - minHeight - minWidth - property - readOnly - required - requiredIndicatorVisible - requiredMessage - themeNames - visible - width
themeNames
The themeNames attribute defines the orientation of items.
By default, items are arranged horizontally.
Handlers
AttachEvent - ClientValidatedEvent - ComponentValueChangeEvent - DetachEvent - TypedValueChangeEvent - itemEnabledProvider - itemLabelGenerator - statusChangeHandler - validator
Чтобы сгенерировать заглушку обработчика в Jmix Studio, используйте вкладку Handlers панели инспектора Jmix UI, или команду Generate Handler, доступную на верхней панели контроллера экрана и через меню Code → Generate (Alt+Insert / Cmd+N). |
See Also
See the Vaadin Docs for more information.