我正在使用将数据绑定到表单binder.addStatusChangeListener( ... )
中的部分代码,检查我的 web 应用程序中的返回值。从中得出的MCVE是:
人豆
public class Person implements Serializable {
private String name;
public Person() {}
public Person( final String name ) {
this.name = name;
}
public String getName() {
return name;
}
public void setName( final String name ) {
this.name = name;
}
}
人物视图
public class PersonView extends VerticalLayout {
private final Person person = new Person( "Gerold Broser" );
private final TextField name = new TextField( "Name:" );
private final BeanValidationBinder<Person> binder =
new BeanValidationBinder<>( Person.class );
private final Button button = new Button( "Button" );
public PersonView() {
super();
binder.bindInstanceFields( this );
binder.setBean( person );
addComponent( name );
addComponent( button );
binder.addStatusChangeListener( event -> {
final boolean hasChanges, isValid;
out.println( "hasChanges=" + (hasChanges = event.getBinder().hasChanges()) );
out.println( "isValid=" + (isValid = event.getBinder().isValid()) );
button.setEnabled( hasChanges && isValid );
} );
}
}
只要我TextField
在浏览器中更改 's 的内容,我就会得到以下输出:
hasChanges=false
isValid=true
这是一个错误还是我错过了什么?