class Address{
private String street;
...
getters/setters
...
}
bind the form to the datasource
vendor = new Vendor();
vendor.setAddress(new Address());
form = new ViewBoundForm(new VendorFormView());
form.setImmediate(true);
form.setItemDataSource(new BeanItem<Vendor>(vendor));
formLayout.addComponent(form);
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”));
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);
}