Related to events and listeners


I’ve got the following situation and I’ve been trying to find a way to make this work (read through the Vaadin book and searched on the forums, but no luck). Maybe it’s something really simple and I’m just missing a detail, I don’t know. Here goes:

I have a custom component that among other components has a Table attached to it. I would like to know if there is a way for me to listen to events related to the table from the custom component (like when I create a new item that needs to be inserted into it, or delete an item and so on), but in a way that I could fire this event from anywhere in my application by telling to the table “ok, insert this object, or remove this object” (firing the event from anywhere, passing an object and also telling what kind of operation it’s being triggered, such as an insert or delete).

Anything that might point me in the right direction would be appreciated at this point.


This comes rather late, but:

A table has a Container (one created internally by the table if you don’t specify any), and also acts as a Container itself, proxying operations to the underlying container.

If you have a reference to the container (or the table), and make the modifications through it as opposed to directly, the listeners of the table are notified and the UI is updated (special considerations about synchronization and refresh apply if you are using a background thread).

This means operations like:

Object newItemId = containerDataSource.addItem();


The data source can either be Table.getContainerDataSource(), the table itself or a container you have set as the data source for the table.

See the book chapter about the
data model

You can listen for changes to the set of items by registering an ItemSetChangeListener on the table. Other relevant listeners include PropertySetChangeListener and Property.ValueChangeListener.