我正在尝试在vaadin中开发我的第一个应用程序。我看到了一些组件,布局.....现在我正在尝试学习如何将UI组件与DataModel绑定。
我有这个班级
public class Utente {
private String nome = "Mario";
private String cognome = "Rossi";
public Utente() {
// TODO Auto-generated constructor stub
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
}
和这个CustomComponent
public class MyRegistration extends CustomComponent {
private FormLayout mainLayout;
private Button buttonSalva;
private Utente utente;
private BeanItem<Utente> beanItem;
private FieldGroup fieldGroup;
public MyRegistration() {
buildMainLayout();
setCompositionRoot(mainLayout);
}
private FormLayout buildMainLayout() {
utente = new Utente();
beanItem = new BeanItem<Utente>(utente);
fieldGroup = new FieldGroup(beanItem);
mainLayout = new FormLayout();
setWidth("100.0%");
setHeight("100.0%");
mainLayout.addComponent(fieldGroup.buildAndBind("Nome", "nome"));
mainLayout.addComponent(fieldGroup.buildAndBind("Cognome", "cognome"));
// buttonSalva
buttonSalva = new Button();
buttonSalva.setCaption("Salva");
mainLayout.addComponent(buttonSalva);
addListener();
return mainLayout;
}
private void addListener(){
buttonSalva.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
System.out.println(fieldGroup.getItemDataSource());
}
});
}
}
我的麻烦在于,如果我按下按钮,如果我修改了字段的内容,我也会一直显示Mario Rossi。
哪里错了?
答案 0 :(得分:3)
您必须通过说
来提交更改fieldGroup.commit();
或将字段组设置为非缓冲模式:
fieldGroup.setBuffered(false);