I have a Bean that looks like this
Class Person{
private String name;
private int age
private Properties attributes
public String getName() { return name; }
public int getAge() { return age; }
public Properties getAttributes () { return attributes; }
public void setName(String name) { this.name=name; }
public void setAge(int age) { this.age=age; }
public void setAttributes (Properties attributes) { this.attributes = attributes; }
}
Trying to use Vaadin Forms to allow the editing of the Bean, i assign the Bean to the form using
form.setItemDataSource(new BeanItem<Person>(person));
The form displays correct with the attributes showing “{eye.colour=green,hair.colour=brown}”
But when trying to commit any changes, a Conversion error is thrown in regards to Properties.< Init > not having a string constructor.
How can Vaadin Forms handle Beans with non primitive types properties ?
You’ll have to create a custom fieldfactory for the form by extending DefaultFieldFactory.
See https://vaadin.com/book/-/page/components.form.html (half way through the page on how to do this). This will allow you to override the default way form fields are generated. This however doesn’t provide an easy way to handle custom fields and conversions like you want.
Luckily though there is a good extension, which I use, to easily create custom fields and property conversions named the custom field plugin.
https://vaadin.com/directory#addon/customfield
With this component you can easily extend existing fields and add custom conversions.
Since there aren’t many examples on how to do this out there, here is an example of how the various parts of a custom FieldFactory with a custom field work together.
public class CustomFieldFactory extends DefaultFieldFactory {
}