checkbox

checkbox is a component with two states: selected or deselected.

  • XML element: checkbox

  • Java class: JmixCheckbox

Basics

An example of checkbox:

<checkbox label="Create new document"
          value="true"/>
check box basics

Data Binding

You can bind a component to an entity or its attributes hold in a data container.

To bind checkbox 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.

The entity attribute must be of Boolean type.

<data>
    <instance id="userDc"
              class="com.company.onboarding.entity.User">
        <fetchPlan extends="_base"/>
        <loader/>
    </instance>
</data>
<layout>
    <checkbox label="Active"
              dataContainer="userDc"
              property="active"
              id="checkbox"/>
</layout>
check box binding

Attributes

ariaLabel

MDN

Set the accessibility label of this checkbox.

indeterminate

Set the indeterminate state of checkbox.

As according to the HTML5 standard, this has only effect on the visual appearance, not on the checked value.

value

Defines the value of checkbox. Can be true or false.

Handlers

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

ClickEvent

com.vaadin.flow.component.ClickEvent is sent when the user clicks checkbox.

@Autowired
private Notifications notifications;

@Subscribe("checkbox")
public void onCheckboxClick(final ClickEvent<Checkbox> event) {
    if (Boolean.TRUE.equals(event.getSource().getValue())) {
        notifications.create("set")
                .show();
    } else {
        notifications.create("not set")
                .show();
    }
}

Elements

See Also

See the Vaadin Docs for more information.