I'm working on Vaadin, I'm trying to print data in a grid. I want to select this data. Previously I wanted to edit the data but it seems to be before the edit.[I took a look to : https://vaadin.com/docs/-/part/framework/components/components-grid.html#figure.components.grid.editing]
But when I have more then one row, it will always edit or select my first row.
See: Before any edit/select, it print the good values :
But when I try to edit/select the second row (just click on it), I have :
That should be the user id :2, the first name :wc, the last name : sdsdf, ...
My code is :
grid.setItems(getUsersInfo());
grid.addColumn(UserInfo::getUserId).setCaption("User Id");
grid.addColumn(UserInfo::getFirstname).setCaption("First Name")
.setEditorComponent(firstNameEditor, UserInfo::setFirstName);
grid.addColumn(UserInfo::getLastname).setCaption("Last Name")
.setEditorComponent(lastNameEditor, UserInfo::setLastName);
grid.addColumn(UserInfo::getEmail).setCaption("Email")
.setEditorComponent(emailEditor, UserInfo::setEmail);
grid.addColumn(UserInfo::getAddress).setCaption("Address")
.setEditorComponent(addressEditor, UserInfo::setAddress);
grid.addColumn(UserInfo::getPhonenumber).setCaption("Phone Number");
grid.setSizeFull();
grid.setSelectionMode(SelectionMode.SINGLE);
grid.getEditor().setEnabled(true);
setCompositionRoot(grid);
Any help will be very helpful !Thanks
EDIT : My class UserInfo is a user object (getter and setter) typically :
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
super.setFirstname(firstName);
}
My class _UserInfo is extends from CayenneDataObject :
public void setFirstname(String firstname) {
writeProperty(FIRSTNAME_PROPERTY, firstname);
}
public String getFirstname() {
return (String)readProperty(FIRSTNAME_PROPERTY);
}
EDIT 2 : When I just print the data without edit, I have the same issue when I select one data, my code is :
final VerticalLayout vlayout = new VerticalLayout();
userInfo = getUsersInfo();
grid.setItems(userInfo);
grid.addColumn(UserInfo::getUserId).setCaption("User Id");
grid.setSizeFull();
vlayout.addComponent(new HeaderMenu());
vlayout.addComponent(grid);
vlayout.setSizeFull();
setCompositionRoot(vlayout);
EDIT 3: After debugging step by step, I found where is the issue : the issue is where I get my userId :
The error is:
Exception processing async thread queue
Exception processing async thread queue
org.eclipse.jdt.internal.debug.core.model.JDIType cannot be cast to org.eclipse.jdt.debug.core.IJavaReferenceType
On :
public int getUserId() {
return (getObjectId() != null && !getObjectId().isTemporary()) ? (short) getObjectId()
.getIdSnapshot().get(USERID_PK_COLUMN) : null;
}
I did a bad misake ! I did not need to define getter and sette in the object UserInfo, I should take data from _userInfo