1

我正在尝试在 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。

我哪里错了?

4

1 回答 1

3

您必须通过说来提交更改

fieldGroup.commit();

或将字段组设置为非缓冲模式:

fieldGroup.setBuffered(false); 
于 2013-06-13T11:30:12.933 回答