Hi all, have some trouble with generate fields of form, so for set dataSource to form I use this :
public BeanItem createDefaultItem() {
return new BeanItem(new Feedback());
}
this make code useful, beacuase I can sent whatever Entities I want and through some settings I can decide which fields bind with this code:
public void setConstraints(GridConstraints gridConstraints) {
if (gridConstraints != null && gridConstraints != this.constraints) {
synchronized (this.constraints) {
this.constraints.clear();
for (Map.Entry<Object, GridConstraint> entry : gridConstraints.entrySet()) {
this.constraints.addConstraint(entry.getKey(), entry.getValue());
buildAndBind(createCaptionByPropertyId(entry.getKey()), entry.getKey());
}
}
}
}
but the problem is he binds fields with null values and this null values, don’t know why, are showing in browser(see screen 0)
I also have CustomFieldGroupFieldFactory which provide some conditions, and if no one is true then I use DefaultFieldGroupFieldFactory() for creating fields.
The quiestion is how I can drop this null values from my fields?
and how create a field depending on name for example : I have field name ‘country’(String country;) and in form I need a ComboBox which is populated from a simple static method?
Well, null values have to be represented some way. Strictly speaking a TextField should never be used to represent a value that can be null, as there’s no way to input a null (as it’s semantically different from an empty string). However, if you do want to show null values as empty strings (or some other placeholder string), there’s the TextField.setNullRepresentation method that you can call for the generated field.
To customize the type of the field, use the buildAndBind overload that takes a Class<> parameter, or create the field yourself and use bind instead of buildAndBind. Unfortunately FieldGroupFieldFactory won’t be adequate here as it doesn’t receive enough information to make the choice based on property name.
I suspect that the idea is that in Vaadin 7 you can simply do the custom form creation using the FieldGroup methods directly, something that was not possible in Vaadin 6 so you
needed a FieldFactory. In Vaadin 7, FieldGroupFieldFactory is just meant as a very generic fallback.
I agree, we must use FieldGroup or BeanFieldGroup, but why has been drop out java.lang.reflect.Field from ‘fields system’ , can’t get it or I’m missing something ?