Hello everyone,
i want to user a grid in Vaadin 8. The constructor of the grid should do the item Binding for every property in the given Model.
If i user the code below, i get the error: “java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String”.
I read multiple articles in google to find a solution for the problem, but no answer worked for me.
Please, can anybody say me how to do the DataBinding ?
Grid:
public DataGrid(OrgModelCollection modelCol, Class c){ // Class which is user here is User (see code below)
super(c);
this.setItems(modelCol);
List properties = this.getModelProperties(c); // The method returns the properties of the model. It’s doing fine.
for(String prop : properties){
TextField tf = new TextField();
if(prop.equals("id")){ // id is an integer Property in the User class
Binder<T> binder = new Binder<T>(c);
binder.forField(tf)
.withConverter(new StringToBigIntegerConverter("Please insert a number"))
.bind("id");
binder.bindInstanceFields(this);
this.getColumn(prop).setEditorComponent(tf);
}
}
this.getEditor().setEnabled(true);
}
User class:
public class User extends OrgModel{
public int id;
public String username;
public String password;
..... Getter and Setter of the properties