CheckBox
CheckBox is a component with two states: selected or deselected.
Component’s XML-name: checkBox.
Basics
Usage example:
<checkBox id="checkBox"
caption="Create new document"/>
Selecting/deselecting the CheckBox changes its value: Boolean.TRUE or Boolean.FALSE. You can use getValue() and setValue() methods to get or set the value. Passing null to setValue() changes the value to Boolean.FALSE and unchecks the CheckBox.
Data-aware CheckBox
To create the CheckBox associated with data, use dataContainer and property attributes.
<data>
<instance id="userDc" class="ui.ex1.entity.User">
<loader/>
</instance>
</data>
<layout>
<checkBox dataContainer="userDc"
property="enabled"
caption="User Property"/>
</layout>
In the example above, the screen includes the description of the userDc data container for a User entity with the enabled attribute. The dataContainer attribute of the CheckBox component contains a reference to a data container. The property attribute contains the name of an entity attribute whose value is displayed by the CheckBox. The attribute should have a Boolean type.
Appearance
The appearance of the CheckBox component can be customized using SCSS variables with $jmix-checkbox-* prefix.
Events and Handlers
|
To generate a handler stub in Jmix Studio, select the component in the screen descriptor XML or in the Component Hierarchy panel and use the Handlers tab of the Component Inspector panel. Alternatively, you can use the Generate Handler button in the top panel of the screen controller. |
Validator
Adds a validator instance to the component. The validator must throw ValidationException if the value is not valid.
@Install(to = "checkBoxValid", subject = "validator")
protected void checkBoxValidValidator(Boolean value) {
if (!value)
throw new ValidationException("You must accept the terms of the license");
}
ValueChangeEvent
You can use the ValueChangeListener method to track changes of the CheckBox value. For example:
@Autowired
private Notifications notifications;
@Subscribe("checkBox")
protected void onCheckBoxValueChange(HasValue.ValueChangeEvent<Boolean> event) {
if (Boolean.TRUE.equals(event.getValue())) {
notifications.create()
.withCaption("set")
.show();
} else {
notifications.create()
.withCaption("not set")
.show();
}
}
CheckBox XML Attributes
|
You can view and edit attributes applicable to the component using the Component Inspector panel of the Studio’s Screen Designer. |
align - buffered - caption - captionAsHtml - colspan - contextHelpText - contextHelpTextHtmlEnabled - css - dataContainer - description - descriptionAsHtml - editable - enable - box.expandRatio - height - htmlSanitizerEnabled - icon - id - property - responsive - rowspan - stylename - tabIndex - visible - width