@NotNull annotation on ComboBox<Integer>

I have a model class used by BeanValidationBinder with an attribute like this:

@NotNull(message = "should not be null")
private Integer year;

The corresponding form component is a ComboBox:

    ComboBox<Integer> year = new ComboBox<>();
    year.setItems(2000, 2001, 2002);
    year.setClearButtonVisible(true);
    year.setValue(2000);
    // we need to do this, as the setValue makes the field invalid somehow
    year.setInvalid(false);

When the form has loaded, the combobox is immediately marked as red and shows “should not be null” validation error message unless i add year.setInvalid(false) when constructing the ComboBox. Is this expected behaviour?

Please add information about the used version.

Version is 24.1.10

When you are using the binder, where is the set/readBean call? With that there should not be any error visible (you are currently calling setValue manually)

Indeed, when i populate the backing bean instead of calling setValue it works. I guess it’s the preferred approach anyway when using a Binder. Thanks for pointing this out @quirky-zebra !