'Capture value change event on textfield in table using vaadin

Please support me the problem below.

I have a dialog which contains one table and other components. That table has multi rows and columns. A column contains text fields which is enter data by user.

However, source code is built by some other layers, below:

  1. Dialog component is built by DialogA class
  2. Table component is built by TableB class
  3. TableB call a generator class GeneratorC which generate columns, rows, text fields for this table

If I stay in GeneratorC I can add listener and catch event on text fields in TableB, but I am staying in DialogA I can not catch value change event on that text fields. Although I added listener on TableB but this listener only catch events of column and rows, this listener doesn't catch any events of that text fields.

Actually, i only need catch value change event for text fields. Currently i don't still find any solution for this problem.

The source code segment adds listener to TableB, this source code stay in DialogA:

 TableB.addListener(new Property.ValueChangeListener()
    {
        private static final long serialVersionUID =
        1L;

        @Override
        public void valueChange(
            ValueChangeEvent event)
        {
             String temp = (String)event.getProperty().getValue();
        }
   });

I am looking forward to your answer.



Solution 1:[1]

The listener should be added to the text fields you add in the ColumnGenerator and not to the Table itself:

    private class TextFieldColumnGenerator implements Table.ColumnGenerator {

            private TextField tf;

            @Override
            public Component generateCell(final Table source, final Object itemId,
                    final Object columnId) {
                Item item = source.getItem(itemId);
                        tf.addListener(new FieldEvents.TextChangeListener() {

                @Override
                public void textChange(TextChangeEvent event) {

                    doSomething(event.getText());
                }
            });
    return tf;
    }

I think this should be right, I wrote it outside an IDE so there could be some errors.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AndroidHustle