Grid + beanitemcontainer

Hello, I have a grid backed with beanitemcontainer, I do the following steps:

1.Add beanitem to container → all ok (its toString returns for ex 122342f)
2.Remove all items from bean container ->all ok
3.Add new item to container (its toString returns 757849c before adding to beanitemcontainer)
4.When i select it by clicking on grid for some unknown reason the grid references THE OLD bean (122342f)!

What am I doing wrong?

By “reason the grid references” i mean grid.getSelectedRow() returns THE OLD bean despite that if I check grid.getItemContainer.getItemIds() → there is everything ok.
Please help.

For selection? This might be similar to a problem I had.

Someone in the past told me to turn off multiselect, then turn it back on, and it should refresh the selection to the new bean:


Alisa Lee, thank you for your reply, but that doenst help me unfoortunately.
I have a button that triggers this one:

public void refreshTable() {  //suppose we call it the second time, then...  
  //this really clears all rows in UI
  //strange behavoir comes here: beanItemContainer.getItemsIds() and grid.getContainerDataSourse.getItemIds()
  // returns correct new objects, while UI 
  //displays the old ones!!! even after clearing the grid totally! grid.getSelectedRow() returns OLD BEANS!!!

Finally I found out what’s going on. The problem is that Grid still holds old itemIds that have been removed from the backed container…
so my current solution is replacing:



beanItemContainer.getItem(grid.getSelectedRow()); It would be good If someone explain why.

I think this is due to fact, that Container API is in some places a bit unintuitive due some legacy reasons. Especially with BeanItemContainer case it happens so that in selected use cases itemId (which is syntactically only a id of the item) and the item happens to be the same (this does not necessarily hold for all imaginable Container types). This allows to make some handy short cuts, when you bear in mind possible pitfals like this. So in your case grid.getSelectedRow() is returing itemId which in that small context is promised to be valid reference to the item. And beanItemContainer.getItem() is promised to return reference to valid instance of the item with itemId.

@Tatu Lund: Last time I checked this, I found that grid’s selection model doesn’t clear references it holds on itemIds when you call removeAllItems() on the underlying BeanItemContainer. I don’t know if this is one of the idiosyncracies you describe, but IMHO it’s a small bug (that is easily worked around, but people run into it nevertheless).
It’s especially annoying with multiple selection enabled.

I faced the same issue when I have more than one row in the grid, the fisrt row return correct getSelectedRow but the last row
return the previous value of item.

I added refreshAllRows after each event in the page as below but the error still appear and I’m using last version of vaadin 7.7.9

public void reloadPage() {
    GeneratedPropertyContainer gpc = getGeneratedPropertyContainer();        
    logger.debug("clear form()");
public BeanItemContainer<PaymentPaidProcess> getBeanItemContainer() {

public GeneratedPropertyContainer getGeneratedPropertyContainer() {
GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(getBeanItemContainer());