Re: Data Binding Pojo's to Form field

Hello All,

Can some help me with binding a collection of pojo’s to form field,

If I have a Person bean with firstName, lastName as properties, I can bind

BeanItem personItem = new BeanItem(person);
form.setItemDataSource(personItem);

and create a fieldfactory for each of the propery.

If have a collection Set, how do it bind each element in the collection for form field.

Regards,
Vinay Vemula

One way is to use a BeanItemContainer with the addAll(Collection) or the BeanItemContainer(Collection) constructor. Adding or removing items from the container is supported, but they are not reflected in the collection object, as the container is not bound to it but the contained objects.

The CollectionContainer add-on is an alternative, although I don’t see much benefit. Adding and removing items from the collection through the container interface is also not supported.

But, you can’t bind a container (or collection) to a form, which is an editor for a single
item
, not for a container that contains many items. You may want to use some sort of master-detail view, such as the one in
this example
.

Thanks alot Marko