Reputation: 791
I'm having some problems when I use Vaadin's Grid with BeanItemContainer. It displays a row OK, but when I try to save edited row it throws:
java.lang.IllegalArgumentException: Given item id (uz.sample.backend.entity.MyBean@4d949367) does not exist in the container
at com.vaadin.ui.Grid$AbstractSelectionModel.checkItemIdExists(Grid.java:1367)
at com.vaadin.ui.Grid$SingleSelectionModel.select(Grid.java:1457)
at com.vaadin.ui.Grid$SingleSelectionModel$1.select(Grid.java:1442)
Then if I click again save button it throws:
com.vaadin.data.fieldgroup.FieldGroup$CommitException: Property "organConductedCourse" not bound to datasource.
at com.vaadin.data.fieldgroup.FieldGroup.startTransactions(FieldGroup.java:557)
at com.vaadin.data.fieldgroup.FieldGroup.commit(FieldGroup.java:476)
at com.vaadin.ui.Grid.saveEditor(Grid.java:6817)
at com.vaadin.ui.Grid$4.save(Grid.java:4782)
My code something like this:
Grid grid = new Grid(); grid.setSizeFull(); grid.setEditorEnabled(true); BeanItemContainer<MyBean> container = new BeanItemContainer<>(MyBean.class); container.addBean(new MyBean()); grid.setContainerDataSource(container);
I don't know where I'm doing wrong. Maybe you have any idea. Thanks for any advise!
Upvotes: 1
Views: 1028
Reputation: 791
I found an answer after some searching again. I had to use BeanContainer
instead of BeanItemContainer
. It turns out that BeanItemContainer
uses the hashCode of each Item to identify the item. So, MyBean
's hashCode()
is based on a field that is changed after edited. Then item was not found and "item id does not exist in the container" error was thrown.(as nobody answered to this question, I took my comment that is a solution as the answer, I hope it will help others)
Upvotes: 1