我最近開始使用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
是的,當我檢查複選框並保存表單時什麼也沒有發生 –