Following is my Bean with field
“age” of type
long
public class Person {
private String name;
private long age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getAge() {
return age;
}
public void setAge(long age) {
this.age = age;
}
}
Now when I use BeanFieldGroup for binding a form to this bean i get following validation error
“Could not convert value to Numnber” .
Any thoughts about fixing this issue?
The “proper” way to do this is to create your own “converter” so Vaadin’s field components can work with it. There’s
a page in the wiki with the details.
If you don’t want to create a converter, maybe you can:
change “private long age” to “private Number age” in the pojo. (might not be feasible if this is coming from a database)
assuming this is a DTO that you can modify, you can add an additional data member with the expected type, and do the conversion in the getter/setter. Then bind the Field components to the new data member instead.
public class Person {
private String name;
private long age;
private Number ageInNumber;
public Number getAgeInNumber() {
Number value = ....; // convert age to value
return value;
}
public void setAgeInNumber(Number value) {
this.age = ..... //convert value to age
}