In vaadin 7 com.vaadin.ui.ComboBox
there was removeAllValidators()
. Is there a replacement for removeAllValidators()
in vaadin 8?
In Vaadin 8, and also in subsequent Vaadin 10,14, versions validator API is not directly in the fields anymore. Instead Vaadin 8 introduced a new concept called Binder , which handles data binding with Validator - Converter chain.
With Binder you can form the Validator - Converter chain using builder pattern, see example below
binder.forField(yearOfBirthField)
// Validator will be run with the String value of the field
.withValidator(text -> text.length() == 4,
"Doesn't look like a year")
// Converter will only be run for strings with 4 characters
.withConverter(
new StringToIntegerConverter("Must enter a number"))
// Validator will be run with the converted value
.withValidator(year -> year >= 1900 && year < 2000,
"Person must be born in the 20th century")
.bind(Person::getYearOfBirth, Person::setYearOfBirth);
The rough equivalent to old Vaadin 7, field.removeAllValidators() is
binder.removeBinding(yearOfBirthField);
The Binder is typed with Bean, which you use with your form. If you have only a single field, then Binder may be an overkill, and you may use FieldBinder add-on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.