CheckBox validation via validateUiComponents

I have a simple CheckBox which needs to be checked in order to save a page.

I am using screenValidation.validateUiComponents(formName) to get the errors of the form and it works fine for other fields in that form. However the CheckBox returns no error regardless if it’s checked or not.

I have tried @NotNull as well as @AssertTrue in the entity java file but it didn’t show any validation message. Any idea why?

Hello,

could you clarify which version of CUBA framework do you use? I’ve tried to add
javax.validation.constraints.AssertTrue on my Boolean field in the entity and validation catch the “exception”.

You can also add your custom validation to the field:

@Inject
private CheckBox checkBox;

@Subscribe
public void onInit(InitEvent event) {
    checkBox.addValidator(value -> {
        if (!Boolean.TRUE.equals(value)) {
            throw new ValidationException("Value should be true");
        }
    });
}