String Combobox of Integer values with CustomValueSetListener

Hello,

I am using Vaadin 14.1.21 and want a Dropdown box (Combobox) to display Integer-values, and also allow custom input.

I have Integer in the dataclass for the field as a type, but the UI fieldtype is String since I also need to enable custom input, .
I use withConverter in combination with a custom converter as I don’t want to display the thousand-separator (dot in my case) in the UI.
It works as expected for all supplied drop down items - and when I select the supplied ‘invalid’ item of the dropdown menu (“Error Message Item”), I get my custom error displayed beneath the combobox.

The problem appears when I input an invalid custom value, e.g. “329hhh2” - I get no error upon invalid custom-input from my custom converter!

I don’t get any error at all and when I want to “save” my object, the (invalid) combobox value just disappears into nirvana and I get Null as the field-value.

Can someone tell me what I’m doing wrong?

Here is my minimal code example:


public class RisikoForm extends Div {

	private ComboBox<String> number_string_combobox;

	public void instantiate_string_combobox() {
		number_string_combobox = new ComboBox<>();
		number_string_combobox.setItems("6583212", "114514", "879278", "Error Message Item");
		number_string_combobox.setLabel("Number");
		number_string_combobox.addCustomValueSetListener(event -> event.getDetail());
	}


	private static class Id_StringToInteger_Converter extends StringToIntegerConverter {

		public Id_StringToInteger_Converter() {
			super("Custom Error: Input cannot be converted to integer");
		}

		@Override
		protected NumberFormat getFormat(Locale locale) {
			final NumberFormat format = super.getFormat(locale);
			format.setGroupingUsed(false);
			return format;
		}
	}

	public Form(ViewLogic sampleCrudLogic) {
		this.instantiate_string_combobox();
		content.add(number_string_combobox);

		binder = new BeanValidationBinder<>(Data.class);
		binder.forField(number_string_combobox)
			  .withNullRepresentation("")
			  .withConverter(new Id_StringToInteger_Converter())
			  .bind(Data::getIntegerNumber, Data::setIntegerNumber);
	}
}


public class Dataclass implements Serializable {

   private Integer integerNumber;
   
    public Integer getIntegerNumber() {
        return integerNumber;
    }

    public void setIntegerNumber(Integer integerNumber) {
        this.integerNumber = integerNumber;
    }

}

Found my own mistake…

addCustomValueSetListener(event -> number_string_combobox.setValue(event.getDetail()))

I forgot to set the value.
It still doesn’t check the custom input for the combobox “EAGER”, but that I can live with.

Has the getDetail() method been removed? I cannot for the life of me to call it. I don’t understand what the problem is.