Dear all,
I’m trying to display the contents of a database table in a page using the Table object. I have no issues connecting to the database and am able to list one of the table fields with a Select object. I’m using the code below, I get no errors but no Table is shown in the page. With the debugger I’ve been able to verify that the query is sucessful and the users list contains the correct items when it is passed to the BeanItemContainer.
Any hint on why this code doesn’t work would be very helpful. Thank you.
contentView = new Table();
contentView.setWidth("100%");
contentView.setHeight(400);
contentView.setImmediate(true);
contentView.setSortDisabled(false);
contentView.setNullSelectionAllowed(true);
contentView.setTableFieldFactory(new UserTableFieldsFactory());
contentView.setEditable(true);
contentView.setSelectable(true);
contentView.setMultiSelect(true);
contentView.setColumnHeader("companyname", "Compagnie");
contentView.setColumnHeader("email", "E-mail");
contentView.setColumnHeader("function", "Fonction");
contentView.setVisibleColumns(new Object[] {
"companyname",
"email",
"function"
});
contentView.setColumnHeaders(new String[] {
"Compagnie",
"E-mail",
"Fonction"
});
tabP.addComponent(contentView);
loadUsers();
protected final void loadUsers(){
Query q = PM.getInstance().createQuery("select u from " + User.class.getSimpleName() + " u");
List<User> users = q.getResultList();
userContainer = new BeanItemContainer(User.class, users);
contentView.setContainerDataSource(userContainer);
}