我最近开始使用vaadin框架。如何将checkBox绑定到布尔属性?
我有一个表单,其中包含一些textFields和一个复选框,我的问题是所有的字段都与它们的属性绑定在一起期望checkbox ??。
这是形式:
public class ContactForm extends FormLayout {
private Button save = new Button("Save", this::save);
private Button delete = new Button("Delete", this::delete);
private Button cancel = new Button("Cancel", this::cancel);
private TextField firstName = new TextField("First name");
private TextField lastName = new TextField("Last name");
private TextField phone = new TextField("Phone");
private TextField email = new TextField("Email");
private DateField birthDate = new DateField("Birth date");
private CheckBox bookMarks = new CheckBox("BookMarks");
private Contact contact;
// Easily bind forms to beans and manage validation and buffering
private BeanFieldGroup<Contact> formFieldBindings;
public ContactForm() {
configureComponents();
buildLayout();
}
private void configureComponents() {...}
private void buildLayout() {...}
void edit(Contact contact) {
this.contact = contact;
if (contact != null) {
// Bind the properties of the contact POJO to fields in this form
formFieldBindings = BeanFieldGroup.bindFieldsBuffered(contact, this);
delete.setVisible(contact.getId() != null);
}
setVisible(contact != null);
}
@Override
public AddressbookUI getUI() {
return (AddressbookUI) super.getUI();
}}
这是我的类联系人:
public class Contact implements Serializable, Cloneable {
private Long id;
private String firstName = "";
private String lastName = "";
private String phone = "";
private String email = "";
private Date birthDate;
private Boolean bookMarks;
// getters and setters
...
}
我到底做错了什么?我应该手动绑定复选框字段吗?
至于我所知'默认状态的复选框(未选中,FALSE).' – soorapadman
,能得到任何问题? – soorapadman
是的,当我检查复选框并保存表单时什么也没有发生 –