teamForm.setFormFieldFactory(new DefaultFieldFactory() {
@Override
public Field createField(Item item, Object propertyId,
Component uiContext) {
Field field = null;
if ("manager".equals(propertyId)) {
// The Team bean has a Person instance, whereas the
// value of a ComboBox here is an identifier.
ComboBox select = new ComboBox("manager",
getPersonContainer());
select.setItemCaptionPropertyId("firstName");
field = new BeanFieldWrapper<Person>(select,
Person.class, getPersonContainer(), "lastName");
} else if ("members".equals(propertyId)) {
// The Team bean has a Set of Person, whereas the value
// of a TwinColSelect here is a set of identifiers.
// Therefore, we need to convert between the two sets.
TwinColSelect select = new TwinColSelect(null,
getPersonContainer());
select.setMultiSelect(true);
select.setItemCaptionPropertyId("firstName");
field = new BeanSetFieldWrapper<Person>(select,
Person.class, getPersonContainer(), "lastName");
field.setCaption(createCaptionByPropertyId(propertyId));
} else {
field = super.createField(item, propertyId, uiContext);
if (field instanceof TextField) {
// show null as an empty string
((TextField) field).setNullRepresentation("");