Best way to refresh bean in beancontainer with updated data?

What is the best way to refresh a bean in a beancontainer with update data?

I have a bean container that contains some beans, in some circumstances (such as an undo of changes) I want to go back to the database and refresh the record with the current record image. I do not want to change the position of the record in the bean container, I just want to replace the bean with the new and updated data from the server.

How would I best go about doing this? Is the best way to get the index of the record currently, delete it, and then add it back at that index?

Thank you

Since no one has responded, here is what I am doing. If this is not the best way then let me know.

  1. I get the index of the bean using the key for the bean.
  2. If the key exist in the container, I then do the following
  3. Delete the existing bean from the container
  4. Add the updated version of the bean back to the container using the index that I got in step 1
  5. If the key does not exist I add the new bean into the container.

Again it would be nice to know if this is the correct way to handle this. Also it would be nice if this was a standard function of the bean container.

Thank you

This is something I’ve come up against as well. The data package and binding is (IMHO) a weak point in vaadin as it is handled much better in other frameworks.

The approach you outlined will work as long as there are no Item.Viewer(s) using the item you replace in steps 1-2 as an item datasource and there are no Property.Viewer(s) using any properties of the item as a property datasource. If you need to handle these cases, I’d recommend updating the properties of the item using the data APIs.

Person refreshedBean = refreshFromDb()

BeanItem refreshedBeanItem = new BeanItem<>(bean)

Item itemToRefresh = getItemFromContainer()

// sets property values of itemToRefresh to be the same as on refreshedBeanItem
for (Object propertyId: beanItem.getItemPropertyIds()) {
[/code]Alternatively you could implement your own container (extends AbstractContainer) which has this functionality.