How to prevent show text "null"
when using Binder
withConverter
method
TextField id = new TextField("Id");
TextField name = new TextField("Name");
Binder<Customer> b = new Binder<>();
b.forField(id)
.withConverter(Integer::valueOf, String::valueOf, "Invalid")
.bind(Customer::getId, Customer::setId);
b.forField(name)
.bind(Customer::getName, Customer::setName);
b.readBean(customer);
And the result is it:
How do the conversion without losing the validation type?
Finally, I found a solution using the vaadin API, thanks for the help @Shirkam
b.forField(id)
.withConverter(Integer::valueOf, String::valueOf, "Invalid")
.withNullRepresentation(0)
.withValidator(new IntegerRangeValidator("Value must be greater than 0 ", 1, null))
.bind(Customer::getId, Customer::setId);
b.forField(name)
.bind(Customer::getName, Customer::setName);
b.readBean(customer);