Understanding generated columns

Sometimes you need to calculate the content of one column based on the content of other columns. Generated columns are just great for accomplishing that. Suppose you have a table with two Integer columns:

    Table table = new Table();
    table.addContainerProperty("A", Integer.class, 0);
    table.addContainerProperty("B", Integer.class, 0);

You want a third column with the sum of the previous columns. Here is the code to do that:

    table.addGeneratedColumn("A + B", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, Object columnId) { Integer a = (Integer) source.getItem(itemId) .getItemProperty("A").getValue(); Integer b = (Integer) source.getItem(itemId) .getItemProperty("B").getValue(); ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.