vaadin 8 ComboBox:removeAllValidators

问题描述 投票:1回答:1

[vaadin 7 com.vaadin.ui.ComboBox中有removeAllValidators()。vaadin 8中是否有removeAllValidators()的替代品?

combobox vaadin7 vaadin8
1个回答
1
投票

在Vaadin 8和后续的Vaadin 10,14中,版本验证器API不再直接在字段中。相反,Vaadin 8引入了一个称为Binder的新概念,该概念可通过Validator-Converter Chain处理数据绑定。

使用Binder,您可以使用构建器模式形成Validator-Converter链,请参见下面的示例

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);

与旧的Vaadin 7等效,field.removeAllValidators()为

binder.removeBinding(yearOfBirthField);

活页夹是用Bean键入的,可在表单中使用。如果您只有一个字段,则活页夹可能是一个过大的杀伤力,您可以使用FieldBinder附加组件。

© www.soinside.com 2019 - 2024. All rights reserved.