I am surely goofing at something but I do not understand where. Here is a simplistic example to reproduce what happens.
I have a table containing Person beans with two fields: firstName and lastName, plus a computed column fullName that is the concatenation of both. firstName and lastname are editable and I expect that if I change any of them fullName reflects the changes but nope!
I also tried to change the field factory to make immediate all generated fields, and I see (with a change listener not shown for simplicity) that fields are actually updated, but the computed field does not change.
Here is the code:
private class MyTable extends Table {
private PersonContainer container = new PersonContainer();
MyTable() {
setSelectable(true);
setMultiSelect(true);
setImmediate(true);
setEditable(true);
setContainerDataSource(container);
addGeneratedColumn("fullName", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Person p = container.getItem(itemId).getBean();
String fullName = p.getFirstName() + " " + p.getLastName();
return new Label(fullName);
}
});
setVisibleColumns("firstName,lastName,fullName".split(","));
}
}
class MyTableFactory extends DefaultFieldFactory {
private TableFieldFactory delegate = DefaultFieldFactory.get();
@Override
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
Field result = delegate.createField(container, itemId, propertyId, uiContext);
if (result instanceof AbstractComponent) {
((AbstractComponent) result).setImmediate(true);
}
return result;
}
}
private class PersonContainer extends BeanItemContainer<Person> {
public PersonContainer() throws IllegalArgumentException {
super(Person.class);
addBean(new Person("Joe", "Bosta"));
addBean(new Person("Cecilia", "Santiago"));
}
}
public static class Person {
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return firstName + " " + lastName;
}
}