1

Hi I am trying to validate IntegerField using Binder with this code:

binder.forField(number)
.withValidator(num -> num == null || (num >= 1 && num <= 999),
        getTranslation("number_must_be_between_1_and_999"))
    .bind(BusinessObject::getNumber, BusinessObject::setNumber);

The field is optional, but if entered, must be between 1 and 999. It works fine until I try to enter a number greater than 2147483647 (the maximum Intger in Java). For numbers greater than this, the validation passes without any warning, and the background business object gets a null value. The field is in a dialog and what makes it even weirder is that the next time I open the same dialog, the IntegerField contains an invalid number entered even though null is written to the business object, Binder.readBean() stops working for that field. How can I validate IntegerField correctly and avoid this bug and why is it not possible to limit the number of digits for an IntegerField? I am using Vaadin 23.3.0 .

saleksand
  • 11
  • 2
  • 1
    You're probably facing this issue: https://github.com/vaadin/flow-components/issues/1035; workaround would be to use a TextField instead. – ollitietavainen Feb 16 '23 at 06:56

0 Answers0