Fill table with values based on another data value

I have a container that represents the following fields:

  • Name
  • Surname
  • Married
  • Wife’s Name
  • Wife’s Surname

“Married” column is represented by checkbox. And its state is calculated from Wife’s Name/Surname values. If they are empty, checkbox is false, otherwise - true.

How to fill table with true/false values if there’s no field “married” in a bean and there’s no opportunity to add such field?

Here’s some code:

public class PersonData implements Serializable {
    private String name = "";
    private String surname = "";
    private String wifeName = "";
    private String wifeSurname = "";
    
    //getters and setters
public class PersonInfoContainer extends BeanItemContainer<PersonData> implements Serializable {
    public static final Object[] NATURAL_COLUMN_ORDER = {"name", "surname", "married", "wifeName", "wifeSurname"};

    public static final String[] COLUMN_HEADERS = {"Name", "Surname", "Married", Wife's Name", "Wife's Surname"};

    public PersonInfoContainer() throws InstantiationException, IllegalAccessException {
        super(PersonData.class);

//Retrieves server list and fills container with corresponding data
    public static PersonInfoContainer getAllPersons() {
        PersonInfoContainer container = null;
        try {
            container = new PersonInfoContainer();
            List<PersonData> persons = /*call method that returns list of persons from DB*/

            for(PersonData person : persons) {
                container.addItem(person);
            }
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }

        return container;
    }
}
public class PersonList extends Table {
    public PersonList(PersonApp app) {
        //Expand to the whole available space
        setSizeFull();

        setColumnCollapsingAllowed(true);
        setColumnReorderingAllowed(true);

        //Fill table
        setContainerDataSource(app.getPersonDataSource());
        setVisibleColumns(PersonInfoContainer.NATURAL_COLUMN_ORDER);
        setColumnHeaders(PersonInfoContainer.COLUMN_HEADERS);

        //Make table selectable and react immediately to user events
        setSelectable(true);
        setImmediate(true);
        addValueChangeListener(app);
        //User cannot deselect a row
        setNullSelectionAllowed(false);
    }
}
public class PersonApp extends VerticalLayout implements Button.ClickListener, Property.ValueChangeListener{
    private PersonInfoContainer personInfoDataSource = PersonInfoContainer.getAllPersons();

A couple of possibilities, depending on whether you simply want a column in the table, or a real property

  • create a delegating PersonData that simply wraps PersonData and adds a new derived “married” propertiy
  • create a
    Generated Column

I suspect GeneratedColumn is what you want, though.

Cheers,

Charles

GeneratedColumn looks great but I haven’t managed yet to embed it.
I will continue experimenting, hope I’ll be able at last to add this column.