I have an editor enabled grid, and I was trying to figure out how to get the bean from the container when it’s being edited by a user.
What I really want is to send the item’s changes that the user made after hitting save back to the database, but I can’t figure out how to access the bean? This is all I could figure out.
[code]
resultsGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler(){ @Override
public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {
personList.getIdByIndex(resultsGrid.getEditedItemId());
} @Override
public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException{
}
})
[/code]I think I can get it to return an object, but not the bean? If I could at least the the row’s data (Name and Num) or the row number it’s editing, maybe I could come up with something. But I’m really not sure what I’m doing. Does anybody have any hints?
Additonally, if you are using a BeanItemContainer, then you can also get the bean through the commit event. For example, if we have the following bean object:[color=#5b7f8b]
[/color][code]
public class GridExampleBean {
private String name;
private int count;
public GridExampleBean(String name, int count) {
this.name = name;
this.count = count;
}
public String getName() {
return name;
}
public int getCount() {
return count;
}
public void setName(String name) {
this.name = name;
}
public void setCount(int count) {
this.count = count;
}
@Override
public String toString() {
return String.format("Name: %s, count: %s", name, count);
}
}
[/code]
Then in the commit event handler, you can access the bean itself, such as:
edit: ok I got it now, for some reason when I tried the lambda the IDE didn’t show me all available methods and I was kinda irritated why the editorSaveEvent wouldn’t give me access to the commited data. But of course it does.