Events when editing the values of a table


I want to display values in a table which should be editable.
I therefore looked at the section “Editing the Values of a Table” in the Reference Manual. There it is described how to make a table editable - and yes it works.

But how do I get the changed values back in my objects?
And what do I have to do to get a change event when a cell value has changed?

I read the posts in the forum but did not really found a complete solution which showed all pieces required.

Can you give a simple example showing how storing values back to may objects should work and how I can handle change event - may be by extending the example in the Reference Manual (which otherwise explains a lot of the material very well).


The way I’d do it would probably be by using a bean container instead of a indexed container that you are probably using right now.

The idea is that you make beans out of your object, the beans are then put into the beancontainer and onwards to the table. When you modify the table, it modifies the bean on the same time. Modifying the bean will automatically modify the object correspondingly. Is this what you are looking for?

There is one implementation of a beancontainer shipped within the toolkit package. In the download package, go under WebContent/WEB-INF/lib and you find the .jar there. I remember that there is some kind of an article on how to use it but I can’t find one right now. Poke around a little bit and you’ll notice how it is supposed to be used. It is very close to IndexedContainer with the addition of generics (for you object).

I’d be happy to help if this raises any more questions.

Thank you for your feedback.

I will try to find an example use of BeanContainer within the toolkit package.
This will help to get the edited values back into my objects.

What about the event listener? Let say, I want to validate all edited fields immediately? How can I get an cell-changed event for my table?


Hmm… I guess you could create a fieldfactory and give it to the table with table.setFieldFactory(myFactory). I guess the table has one from the start but it doesn’t do anything that complex.

Manual section “4.15.3. Validating Form Input” shows how to give a validator to one field and “4.15.2. Binding Form to Data” shows how to create a fieldfactory. Combining these two should solve it.

By the way, 4.15.2 also contained an example on how beanItems work. This is about what I meant with the BeanContainer. The principle is the same - you change the field and the original objects changes at the same time. Just remember to give field.setImmediate(true) to all your fields.