gpt4 book ai didi

java - 如何将字段绑定(bind)到bean vaadin中的外键

转载 作者:行者123 更新时间:2023-11-30 03:55:50 25 4
gpt4 key购买 nike

我的 bean 是这样的

   public class RegistrationEntity 
{
private Long accountNumber;
private String firstName;
private String middleName;
private String lastName;


// occupation entity is another table
private OccupationEntity occupationEntity;
}

组件是这样的

 firstName = new TextField("First Name");
firstName.setRequired(true);
firstName.setWidth(COMMON_FIELD_WIDTH);



lastName = new TextField("Last Name");
lastName.setRequired(true);
lastName.setWidth(COMMON_FIELD_WIDTH);


occupation = new NativeSelect("Occupation:");
occupation.setRequired(true);
occupation.setImmediate(true);
occupation.setWidth(COMMON_FIELD_WIDTH);
occupation.setNullSelectionItemId("--Select--");
occupation.addItem("Static");

只要考虑firstName和lastName就可以这样绑定(bind)

  fieldgroup.bind(firstName,"firstName");

但是我怎样才能将职业NativeSelect绑定(bind)到职业实体??????

最佳答案

对于这种情况,您可以使用BeanFieldGroup和自定义FieldGroupFieldFactory:

binder = new BeanFieldGroup<RegistrationEntity>(RegistrationEntity.class);
binder.setFieldFactory(new FieldGroupFieldFactory() {
private DefaultFieldGroupFieldFactory defaultFactory = new DefaultFieldGroupFieldFactory();
@Override
public <T extends Field> T createField(Class<?> dataType, Class<T> fieldType) {
if ("OccupationEntity".equals(dataType.getName())) {
BeanItemContainer<OccupationEntity> occupationEntityContainer = new BeanItemContainer<OccupationEntity>(OccupationEntity.class);
occupationEntityContainer.addAll(allEntities);
Field field = new Combobox("Occupation:", occupationEntityContainer);
((Combobox) field).setItemCaptionPropertyId(--Insert caption bean property here--);
((Combobox) field).setNullSelectionAllowed(false);
return fieldType.cast(field);
}

return defaultFactory.createField(dataType, fieldType);
}
});

binder.setItemDataSource(item);

关于java - 如何将字段绑定(bind)到bean vaadin中的外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23214105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com