O'Reilly logo

Vaadin 7 UI Design By Example Beginner's Guide by Alejandro Duarte

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required