Issue with Table and BeanItemContainer visible columns

In my Panel I have…

		table = new Table();
		addComponent(table);
		
		table.setSelectable(true);
		table.setImmediate(true);

		table.addContainerProperty(CONF_NUM_COL, String.class, null);
		table.addContainerProperty(COMPANY_NAME_COL, String.class, null);
		table.addContainerProperty(SUBMIT_DATE_COL, Date.class, null);

		table.setColumnHeader(CONF_NUM_COL, POYProperties
				.getString(CONF_NUM_COL));
		table.setColumnHeader(COMPANY_NAME_COL, POYProperties
				.getString(COMPANY_NAME_COL));
		table.setColumnHeader(SUBMIT_DATE_COL, POYProperties
				.getString(SUBMIT_DATE_COL));

		SubmissionManager sm = new SubmissionManager();
		List<Submission> submissions = sm.list();

		BeanItemContainer<Submission> container = new BeanItemContainer<Submission>(
				submissions);
		
		table.setVisibleColumns(visibleCols);

		table.setContainerDataSource(container);

However the table is showing all of the fields in my Submission bean (columns I don’t want to display in the Table). What am I doing wrong?

Also, there appears to be an order dependency. If I have this line

table.setVisibleColumns(visibleCols);

before I add my container properties I get the following exception, “Ids must exist in the Container or as a generated column , missing id: confNumber”

Hi, you can do this:


Table table = new Table();
table.setSelectable(true);
table.setImmediate(true);
SubmissionManager sm = new SubmissionManager();
List<Submission> submissions = sm.list();
table.setContainerDataSource(new BeanItemContainer<Submission>(submissions));
table.setVisibleColumns(new String[] { CONF_NUM_COL, COMPANY_NAME_COL, SUBMIT_DATE_COL });
table.setColumnHeaders(new String[] { "Column 1 Description", "Column 2 Description", ""Column 3 Description"" });

Just make sure sumissions collection is not empty or you will have an error.

If you need to show the table, even if sumissions is empty than you can do a workaround like:


boolean empty = beans.isEmpty();
if (empty) {
	beans.add(new Submission());
}
table.setContainerDataSource(new BeanItemContainer<Submission>(submissions));
if (empty) {
	removeAllItems();
}
table.setVisibleColumns(new String[] { CONF_NUM_COL, COMPANY_NAME_COL, SUBMIT_DATE_COL });
table.setColumnHeaders(new String[] { CONF_NUM_COL, COMPANY_NAME_COL, SUBMIT_DATE_COL });

For sure this work around is not the best solution, so any help will be welcome.

Another way is to use the public BeanItemContainer(Class<? extends BT> type) constructor and do something like

    	BeanItemContainer<Submission> bic = new BeanItemContainer<Submission>(Submission.class);
    	for (Submission s : sm.list()) {
    		bic.addItem(s);
    	}
    	table.setContainerDataSource(bic);

Then it does not matter if the list is empty or not.

Awesome Artur.

Thanks.