我正在使用绑定器来绑定和验证 和 .为了获得验证更改的通知,我向绑定程序添加了一个状态更改通知程序。侦听器检查是否返回 false。但是,在组合框中选择有效条目但文本字段中的无效条目后,它将返回 false。因此,即使存在验证错误,它也返回 false。有关最小示例,请参见下文。TextFieldComboBox.hasValidationErrors()
public class TestWindow extends Window {
private final Binder<State> binder;
public TestWindow() {
this.binder = new Binder<>();
ComboBox<String> comboBox = new ComboBox<>("comboBox", List.of("A", "B"));
TextField textField = new TextField("textField");
this.binder.forField(comboBox).bind(State::getComboBox, State::setComboBox);
this.binder.forField(textField)
.withValidator(string -> string.length() > 3, "tmp")
.bind(State::getName, State::setName);
this.binder.addStatusChangeListener( status -> System.err.println(status.hasValidationErrors()));
setContent(new VerticalLayout(comboBox, textField));
}
private class State {
private String name;
private String comboBox;
public State(String name, String comboBox) {
this.name = name;
this.comboBox = comboBox;
}
public String getComboBox() {
return this.comboBox;
}
public void setComboBox(String comboBox) {
this.comboBox = comboBox;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
}
在文本字段中输入一个太短的字符串并在组合框中选择某些内容后,我希望打印出来。true
幕布斯7119047
相关分类