FormBinder nested property

I’m not able to bind nested attributes like

POJO Vendor

class Vendor{
  private String name;
  private Address address


POJO Address

class Address{
  private String street;

bind the form to the datasource

vendor = new Vendor();
vendor.setAddress(new Address());

form = new ViewBoundForm(new VendorFormView());
form.setItemDataSource(new BeanItem<Vendor>(vendor));

Form 1

private TextField streetField;

Form 2

private TextField streetField;

Form 1 and 2 are working for all not nested attributes like the vendors name.

Is there a way to bind nested attributes like Vendor.address.street?


I have never tried anything like this, but I think it should work if you first introduce the nested property in the BeanItem that you are assigning in to the form. Support for “nested properties” in BeanItems was introduced in Vaadin 6.6, but as far as I know it doesn’t work automatically.

Something like this might do the trick:

vendorItem = new BeanItem(vendor);
vendorItem.addItemProperty(“address.street”, new NestedMethodProperty(vendor, “address.street”));


Quick comment on what Matti has suggested.

We have just put in place in one of our projects the NestedProperties in combination with FormBinder and it works perfectly.
One minor detail is eventually if you want to “automate” the binding and addition of nested properties. In such as case, here is a hint on how
to proceded. Here is an automatic way to add nested properties….

    BeanItem<Person> personItem = new BeanItem<Person>(this.person);
    try {
      Map<String,String> beanMap = MyBeanUtils.recursiveDescribe(person);
      for (Entry<String, String> entry : beanMap.entrySet()) {
        personItem.addItemProperty(entry.getKey(), new NestedMethodProperty(this.person, entry.getKey()));
    } catch (Exception e1) {
      throw new RuntimeException("Exception not handled: " + e1, e1);

where MyBeanUtils is an adapatation of the following thread

hope this may help.