Table is not populated with data

Hello, I am new with Vaadin and I have problem. I am 90% sure that I am doing right, but still it is not working :(.

So I have problem with populating the table with data. I have the following method for creating the Table:


private Table factoryMessageBoardHistoryTableElement() {
        Table table = new Table();
        table.setWidth("100%");
        table.setColumnReorderingAllowed(false);
        table.setColumnCollapsingAllowed(false);

        table.addContainerProperty("check_box", Component.class, null);
        table.setColumnHeader("check_box", "");
        table.setColumnWidth("check_box", 30);

        table.addContainerProperty("member_id", String.class, null);
        table.setColumnHeader("member_id", "Member ID");
        table.setColumnWidth("member_id", 300);

        table.addContainerProperty("Message Text", String.class, null);

        table.setSizeFull();

        return table;
    }

then I have a call of next method to populate the table with data:


public void putMessageBoardHistory(List<MessageBoardHistory> history) {
        this.messageBoardHistoryList = history;

        Container container = this.messageBoardHistoryTable.getContainerDataSource();

        for (MessageBoardHistory item : this.messageBoardHistoryList) {
            CheckBox checkBox = new CheckBox();
            container.addItem(new Object[] {
                    checkBox, "A1", "B1"
                    //item.getMemberId(), item.getMessageText()
            });
        }
    }

the code is executing the for loop, I am sure in that.

On web page I see the created table with rows, but rows do not contain anything, event the checkbox is not there. I checked with inspector the HTML is empty, they are not hidden or the height is not 0px.

So what could be the problem?

Thanks.

Hi,

I don’t think you’re properly assigning your values to the properties. Please try the following (and do note that the code’s written directly to the forum so there may be typos):


Container container = this.messageBoardHistoryTable.getContainerDataSource();

for (MessageBoardHistory item : this.messageBoardHistoryList) {
   container.addItem(item);
   container.getContainerProperty(item, "check_box").setValue(new CheckBox());
   container.getContainerProperty(item, "member_id").setValue("A1");
   container.getContainerProperty(item, "Message Text").setValue("B1");
}

4 things you could try:
1.: Try to addItem directly to the Table not the Container: this.messageBoardHistoryTable(new Object[…]
);
2.: Try refreshing the page after you populated the table (not with restartApplication)
3.: Make the table Immediate this.messageBoardHistoryTable.setImmediate(true);
4.: Use System.out.print to check some data after you populated the table like the tables size: messageBoardHistoryTable.size() or a property of the first/last item (this.messageBoardHistoryTable.iterator.next()).getItemProperty(“member_id”) (I’m not sure if that one works exactly in that syntax but i don’t have a dev environment ready right now)