Hi again!
I am using NestedMethodProperty to add properties to my company bean. I got very strange terror message, because I do have a default constructor in my Company class among the other constructors.
Caused by: java.lang.IllegalArgumentException: Class ‘class com.xxxxx.adminTool.domain.Company’ must contain default constructor
at com.vaadin.addon.beanvalidation.BeanValidationValidator.(BeanValidationValidator.java:65)
at com.vaadin.addon.beanvalidation.BeanValidationValidator.addValidator(BeanValidationValidator.java:87)
at com.vaadin.addon.beanvalidation.BeanValidationForm.addField(BeanValidationForm.java:63)
at com.vaadin.ui.Form.setItemDataSource(Form.java:771)
at com.vaadin.addon.beanvalidation.BeanValidationForm.setItemDataSource(BeanValidationForm.java:106)
newCompanyItem.addItemProperty("address1", new NestedMethodProperty(newCompany, "address.address1"));
editorForm.setItemDataSource(companyItem, Arrays.asList("companyName",
"businessId", "vatNumber", "address1"));
public class Company implements java.io.Serializable {
private static final long serialVersionUID = -6779355918409596943L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Short companyId;
@OneToOne(cascade=CascadeType.PERSIST)
private Address address;
private String companyName;
private String businessId;
private String vatNumber;
private String phoneNumber;
@Temporal(TemporalType.DATE)
private Date lastUpdate;
public Company() {
super();
}
I haven’t got knowledge enough to override addField-method in BeanValidationForm. Could someone help me a little bit? So the beanClass is instance of Company and inside the company there is an Address-object and I am trying to use those nested properties like address.address1 etc? I think that this is the problem, beanvalidator just doesn’t work with JPA and beans or is there any another solution?
public void addField(Object propertyId, Field field) {
Item item = getItemDataSource();
field.setPropertyDataSource(item.getItemProperty(propertyId));
Class<? extends T> beanClass = this.beanClass;
if (item instanceof BeanItem) {
beanClass = (Class<? extends T>) ((BeanItem<T>) item).getBean()
.getClass();
}
BeanValidationValidator validator = BeanValidationValidator
.addValidator(field, propertyId, beanClass);
if (locale != null) {
validator.setLocale(locale);
}
super.addField(propertyId, field);
}
Sami