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

Чтобы сгенерировать заглушку обработчика в Jmix Studio, используйте вкладку Handlers панели инспектора Jmix UI, или команду Generate Handler, доступную на верхней панели контроллера экрана и через меню CodeGenerate (Alt+Insert / Cmd+N).

Elements

See Also

See the Vaadin Docs for more information.