0

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:

enter image description here

How do the conversion without losing the validation type?

Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44

1 Answers1

1

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);
Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44