tonix
tonix

Reputation: 6939

Does Vaadin uses the itemId given to the Table.addItem() like a column in Vaadin Table UI component?

just a question about Vaadin's Table component. I have a table created with a TableFieldFactory, and I have noticed that if I count the number of times the TableFieldFactory is called for a Table with e.g. 8 rows and 4 columns, I get 40 as the result (instead of the expected 8 * 4 = 32).

So does Vaadin uses an hidden extra column when creating the table? Does this column contain the itemId given to the Table.addItem() method? Anyway here is the code I used for the field factory:

// UI's static field
public static int counter = 1;

// ... UI's init() method
tbl.setTableFieldFactory(new TableFieldFactory() {

        @Override
        public Field<?> createField(Container container, Object itemId,
                                    Object propertyId, Component uiContext) {
            TextField field = new TextField((String) propertyId);

            counter++;

            // User can only edit the "Numeric field"
            if ("Numeric field".equals(propertyId)) {

                field.setData(itemId);

                // Remeber the field
                valueFields.put((Integer) itemId, field);

                // Focus if it is the first editable value
                if ((Integer) itemId == 0) {
                    field.focus();
                }
            }
            else {
                field.setReadOnly(true);
            }
            return field;
        }
    }); 
 // here counter is 40 for a 8x4 table 

Upvotes: 0

Views: 238

Answers (1)

riddy
riddy

Reputation: 521

I guess the reason is the lazy loading of the vaadin table. I experienced that on the first load the table is initialized with one row (for better response to the user I suppose), after this it is re-initialized with the lazy-loading amount (in your case the whole table) this would explain the extra 8 calls.

Upvotes: 1

Related Questions