Binding an Integer Object To Textfield. Clearing The Field Not Working

Hi everyone. I used Vaadin 7 a few years back and I’m trying to get used to 8. Whenever I start the app, age is showing as invalid. Please see screenshot.


Whenever I clear the fields using the following code:
fName.setValue(“”);
lName.setValue(“”);
age.setValue(“”);
gender.setValue(“”);

The same thing happens with age. The others work, and they are STRINGS. Is it because age an integer or is my binding on the age incorrect? Please take a look. Thank you.

binder.forField(fName).withNullRepresentation(" “).withValidator(fName->fName.length() >= 0, “Cannot be blank!”)
.bind(Student::getfName, Student::setfName);
binder.forField(lName).withNullRepresentation(” “).withValidator(lName->lName.length() >= 0, “Cannot be blank!”)
.bind(Student::getlName, Student::setlName);
binder.forField(age).withNullRepresentation(” “).withConverter(new StringToIntegerConverter(age.toString()))
.withValidator(age->age > 0, “Invalid Age”).bind(Student::getAge, Student::setAge);
binder.forField(gender).withNullRepresentation(” ")
.withValidator(gender->gender.length() >= 0, “Cannot be blank!”)
.bind(Student::getGender, Student::setGender);
binder.setBean(student);
return this;
41011.png

Hey,

if you are using Integer as data type you should check if your value is null or greater than zero.

age -> age == null || age > 0

Greetings

that fixed it. thank you so much michael! im sure i will be back lol. have a nice day