CheckBoxGroup

CheckBoxGroup allows you to select multiple values from a list of options using checkboxes. If you need to choose only one value from the list, you should use the RadioButtonGroup component.

Component’s XML-name: checkBoxGroup.

check box group operations

Basics

The component can take a list of options from a data container. You can use the optionsContainer attribute, for example:

<data>
    <collection id="countriesDc" class="ui.ex1.entity.Country">
        <fetchPlan extends="_local"/>
        <loader id="countriesDl">
            <query>
                <![CDATA[select e from uiex1_Country e]]>
            </query>
        </loader>
    </collection>
</data>
<layout>
        <checkBoxGroup optionsContainer="countriesDc"
                       caption="Countries"/>
</layout>

In this case, the CheckBoxGroup component will display instance names of the Country entity, located in the countriesDc data container, and its getValue() method will return the Collection of selected entity instances.

countries check box group

With the help of the captionProperty attribute, you can choose another entity attribute to display in the component.

Also, you can do the same thing programmatically:

<data>
    <collection id="countriesDc" class="ui.ex1.entity.Country">
        <fetchPlan extends="_local"/>
        <loader id="countriesDl">
            <query>
                <![CDATA[select e from uiex1_Country e]]>
            </query>
        </loader>
    </collection>
</data>
<layout>
        <checkBoxGroup id="countriesCheckBoxGroup"
                       caption="Countries"/>
</layout>

Please note that in the XML descriptor above, we did not assign an optionsContainer to the checkBoxGroup, we will do this programmatically in the controller:

@Autowired
private CheckBoxGroup<Country> countriesCheckBoxGroup;
@Autowired
private CollectionContainer<Country> countriesDc;

@Subscribe
protected void onInit(InitEvent event) {
    countriesCheckBoxGroup.setOptions(new ContainerOptions<>(countriesDc));
}

Options

setOptions()

The setOptions() method takes one of the implementations of the Options interface and enables working with all types of options:

@Autowired
private CheckBoxGroup<Operation> checkBoxGroup;

@Subscribe
protected void onInit(InitEvent event) {
    checkBoxGroup.setOptions(new EnumOptions<>(Operation.class));
}

setOptionsEnum(), setOptionsList() and setOptionsMap() work in the same way as in the ComboBox component.

Optional Descriptions

You can use the setOptionDescriptionProvider() method to generate tooltips for the options of the CheckBoxGroup component:

@Autowired
private CheckBoxGroup<Customer> checkBoxGroupCustomer;

@Subscribe
protected void onInit(InitEvent event) {
    checkBoxGroupCustomer.setOptionDescriptionProvider(customer ->
            "Email: " + customer.getEmail());
}

You can also use the @Install annotation. For example, to generate tooltips for enum values:

@Install(to = "checkBoxGroup", subject = "optionDescriptionProvider")
private String checkBoxGroupOptionDescriptionProvider(Level level) {
    switch (level) {
        case PLATINUM:
            return "Platinum level";
        case GOLD:
            return "Gold level";
        default:
            return "Silver level";
    }
}

Attributes

orientation

The orientation attribute defines the orientation of group elements. By default, elements are arranged vertically. The horizontal value sets the horizontal orientation.