如何从BeanFieldGroup访问TextField?

时间:2014-07-01 12:08:13

标签: vaadin7

如何将BeanFieldGroup值设置为在以下语句中创建的TextField:

private TextField name  = new TextField("Name");
BeanFieldGroup<MyBean> binder = new BeanFieldGroup<MyBean>(MyBean.class);
BeanFieldGroup<MyBean> fieldGroup = new BeanFieldGroup<MyBean>(MyBean.class);


fieldGroup.setItemDataSource(new MyBean());
fieldGroup.bindMemberFields(this);
layout.addComponent(TextField);

我尝试设置

name = (TextField) binder.getField("name");

但是值bean值没有得到指导

提前致谢

1 个答案:

答案 0 :(得分:0)

您正在使用两个BeanFieldGroup对象,绑定在第一个(fieldGroup)并从第二个(绑定器)获取Field。 这对我有用:

public class MyUI extends UI {

@Getter
@Setter
private TextField name = new TextField("Name");

@Override
public final void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout();
    BeanFieldGroup<MyBean> fieldGroup = new BeanFieldGroup<MyBean>(MyBean.class);

    fieldGroup.setItemDataSource(new MyBean());
    fieldGroup.bindMemberFields(this);
    name = (TextField) fieldGroup.getField("name");
    layout.addComponent(name);
    setContent(layout);
}

public static class MyBean {
    @Getter
    @Setter
    private String name;
}
}