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"/>
check box group basics

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:

  1. Specify the name of the data container as the dataContainer attribute value.

  2. 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

themeNames

The themeNames attribute defines the orientation of items.

By default, items are arranged horizontally.

Handlers

To generate a handler stub in Jmix Studio, use the Handlers tab of the Jmix UI inspector panel or the Generate Handler action available in the top panel of the view class and through the CodeGenerate menu (Alt+Insert / Cmd+N).

Elements

See Also

See the Vaadin Docs for more information.