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;
}
});
- I wonder whether it’s “work as design” or not, because there are only 7 records in the table.
- 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