SqlContainer and addGeneratedColumn


I am using SqlContainer and TableQuery to retrieve data from an existing database table and show the data in a Table by setting the table’s datasource to the SqlContainer. Everything works fine and the data is shown as expected.

Table t = new Table();

TableQuery q = new TableQuery("MyTable",
SQLContainer container = new SQLContainer(q);


Now I have some boolean columns in my database and I want to show them as icons. I tried to use a ColumnGenerator for the boolean column and returning a Label field, where I set the icon. But the icon is not shown. It still shows only the content (value) of the column: true / false

Removing the setValue() on the new label field, results that nothing is shown in the table.

  private void addColumnGenerator()
    addGeneratedColumn("theBooleanColumn", new ColumnGenerator()
      public Object generateCell(Table source, Object itemId, Object columnId)
        System.out.println("itemId: " + itemId + ", columnId: " + columnId);
        if (getItem(itemId).getItemProperty("theBooleanColumn").getValue() != null)
          Label l = new Label();
          l.setIcon(new ThemeResource("icons/32/ok_32.png"));
          return l;
        return null;

How can I do this?

I also tried to use addContainerProperty() on the boolean column, but this results in a OperationNotSupportedException.

container.addContainerProperty("theBooleanColumn", Resource.class, null);

Any hints welcome :wink:

You should use an Embedded instead of a Label inside your generateCell method. That’s the way I present icons to the user.

Thanks for the hint to use Embedded - now it looks like expected :slight_smile: