与combobox的vaadin BeanFieldGroup绑定问题

时间:2015-10-30 14:57:06

标签: java vaadin

我不确定我是否理解BeanFieldGroup,但我希望它应该将字段(UI组件)中的值绑定到我的自定义bean(例如POJO)。

我有POJO。

public class JobConfigDTO {

    @Max(50)
    private String format;

    @Max(50)
    private String template;

    @Max(50)
    private String channel;
}

使用此代码,我尝试将我的POJO绑定到复选框。

private void test(){

    JobConfigDTO jobConfigDTO = new JobConfigDTO();
    ComboBox comboChannel = createEditFormCombobox("Channel", "CHANNEL");
    ComboBox comboFormat = createEditFormCombobox("Format", "FORMAT");
    ComboBox comboTemplate = createEditFormCombobox("Template", "TEMPLATE");

    BeanFieldGroup<JobConfigDTO> binder = new BeanFieldGroup<>(JobConfigDTO.class);
    binder.setItemDataSource(jobConfigDTO);
    binder.setBuffered(false);
    binder.bind(comboChannel, "channel");

    binder.bind(comboChannel, "channel");
    binder.bind(comboFormat, "format");
    binder.bind(comboTemplate, "template");

    Button btnSave = new Button("Add");
    btnSave.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                log.debug("jobconfigdto {}", jobConfigDTO);
                binder.setBuffered(true);
                log.debug("jobconfigdto {}", jobConfigDTO);
                binder.commit();
                binder.setBuffered(false);
            } catch (FieldGroup.CommitException e) {
                log.error("Unable to save job config", e);
            }
        }
    });
}

当我在表单中设置组合框的值并单击添加按钮时,pojo JobConfigDTO未填充。

我错过了什么或BeanFieldGroup有另一种用法吗?我想将复选框中的值绑定到我的pojo类,并在最后验证它们。

0 个答案:

没有答案
相关问题