table.addGeneratedColumn() called more than needed.

Hello,

Please refer to
com.vaadin.demo.sampler.features.table.TableStylingExample.java
, there is an interesting scenario when I work with table.addGeneratedColumn().

After I set a break point at
“Item item = table.getItem(itemId);”
and click link “Reset” in the UI,
generateCell()
will be called more than 20 times.

       // Generate the email-link from firstname & lastname
        table.addGeneratedColumn("Email", new Table.ColumnGenerator() {
            public Component generateCell(Table source, Object itemId,
                    Object columnId) {
                Item item = table.getItem(itemId);
                String fn = (String) item.getItemProperty(
                        ExampleUtil.PERSON_PROPERTY_FIRSTNAME).getValue();
                String ln = (String) item.getItemProperty(
                        ExampleUtil.PERSON_PROPERTY_LASTNAME).getValue();
                String email = fn.toLowerCase() + "." + ln.toLowerCase()
                        + "@example.com";
                // the Link -component:
                Link emailLink = new Link(email, new ExternalResource("mailto:"
                        + email));
                return emailLink;
            }

        });
  1. I wonder whether it’s “work as design” or not, because there are only 7 records in the table.
  2. In my application, I try to update a row with 3 checkbox:
...
        table.addGeneratedColumn("FLD_A", new BooleanColumnGenerator());
        table.addGeneratedColumn("FLD_B", new BooleanColumnGenerator());
        table.addGeneratedColumn("FLD_C", new BooleanColumnGenerator());
...

public class BooleanColumnGenerator implements Table.ColumnGenerator {
		
	public BooleanColumnGenerator() {
		super();
	}

	@Override
	public Component generateCell(Table source, Object itemId, Object columnId) {
		Property prop = source.getItem(itemId).getItemProperty(columnId);
		Boolean checked = (Boolean) prop.getValue();			
		CheckBox chkBox = new CheckBox();
		chkBox.setValue(checked);
		chkBox.setReadOnly(true);
		return chkBox;
	}
}

For one row, method generateCell() is called 6 times (Total = N rows in the table * 6) when a row is updated. It looks like unusual.

Thanks,
Watt

Hi.

I stumbled upon something similar when I extended the Table to a new add-on, PagedTable. Without looking at the sampler’s code, I bet it just rebuilds the old container upon reset instead of building a new one. I got feedback about the same thing in my add-on, and it seems that modifying a container while it is attached rerenders everything from scratch for every item you add.

The number ‘six’ you mentioned was a number I also noticed. That was the amount of times Table.refreshRenderedCells() was called from different places inside the Table when you change it’s container. That could surely use some optimization. One additional refreshRederedCells was fired for every item change happening in the container. I had the calls up in the thousands before I noticed the problems.

I’ve described all my findings in the
PagedTable forum thread
but I’ll link separately to the four posts which describe this issue:


http://vaadin.com/forum/-/message_boards/message/246896#_19_message_254517


http://vaadin.com/forum/-/message_boards/message/246896#_19_message_259902


http://vaadin.com/forum/-/message_boards/message/246896#_19_message_259918


http://vaadin.com/forum/-/message_boards/message/246896#_19_message_261750

Thank you Jens and your PagedTable.

  1. I wonder whether the issue can be solved by Component.
  2. When testing your online demo, there are two possible improvements (
    http://vaadin.com/forum/-/message_boards/message/268250
    ).