I am adding a new row to a Grid by adding a BeanItem to the underlying Container as follows:
BeanItem beanItem = new BeanItem(user);
Item item = container.addBean(user);
A new row is successfully appended to the Grid.
My question is: How do I then select that new row so I can something like
grid.editItem(grid.getSelectedRow());
My goal is to have an Add button that adds a new row to my grid, selects that row, then edits that row.
This depends a bit which type of container you use. It seems that you are using BeanItemContainer, in which case BeanItem itself is also the ItemId. This means that you can directly apply grid.editItem(beanItem); in your case.
Hi Tatu
Thank you for your reply, yes I am using a BeanItemContainer.
I tried the following code based on your suggestion:
User user = new User();
BeanItem beanItem = container.addItem(user);
fieldGroup.setItemDataSource(beanItem);
grid.editItem(beanItem);
The last line produces the following error:
Item with id false not found in current container
I wondered if the id in question was the id field of the user bean, so I saved user after creating it and confirmed it had a valid value, however I got the same error.
Any suggestions?
Cheers
Sean
Problem sorted, the following code worked fine:
User user = new User(mainMenuBuilder.getDataAccess());
BeanItem beanItem = container.addItem(user);
fieldGroup.setItemDataSource(beanItem);
grid.editItem(user);