Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Expected bean patterns for nested properties in BeanItemContainer
Hi,
I have what to me, is a simple requirement and from looking at the Book of Vaadin (Address book tutorial especially) I cannot see where I am going wrong.
Requirement: I am using a BeanItemContainer to display POJO contents in a Table. Works fine for simple beans. However, I have some beans that have nested items that need to be displayed.
For example, class Company, has a public method called getName() which returns (scarily) the company name.
I am adding my nested properties like this:
for (String field : getTableColumns()) // Add any nested properties...
if (field.contains("."))
cont.addNestedContainerProperty(field) ;
The method getTableColumns() returns the Bean properties to display in the table. Which in this case, is a Collection<String> object.
I've defined the property as follows: "company.name" The method getCompany() returns an instance of Company, and the Company instance has a method of "getName()"
Problem: I am getting the following error when I attempt to create the table:
Caused by: java.lang.NoSuchMethodException: net.surame.data.JobRole.areCompany()
If I remove the "name" portion of the property and just leave "company" as the property (the Company object has an appropriate toString() method), I then get this error:
Caused by: java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column , missing id: company
What is really throwing me is the "areCompany()" method call. Is there some bean pattern for nested properties that I am not complying with? And in the second case, the method is there, although the object may be null. Is that the issue?
I'm sure I am making a silly mistake, so if anyone can shed some light on this, it would be much appreciated.
Thanks in advance,
Anthony
PS: I am using Vaadin 6.8
PPS: The method that sets the table up is as follows:
protected Table setupTable (final Table table, Collection<T> data)
{
if (null != table)
{
table.setSelectable(true) ;
table.setImmediate(true) ;
table.setNullSelectionAllowed(false);
if (null != data)
{
BeanItemContainer<T> cont = new BeanItemContainer<T> (getBeanClass()) ;
table.setContainerDataSource(cont ) ;
for (String field : getTableColumns()) // Add any nested properties...
if (field.contains("."))
cont.addNestedContainerProperty(field) ;
for (T item : data)
cont.addBean(item) ;
Object[] cols = null ;
if (null != getTableColumns() )
cols = getTableColumns().toArray() ;
if (null != cols && cols.length > 0)
table.setVisibleColumns(cols) ;
}
table.addListener(new Property.ValueChangeListener()
{
private static final long serialVersionUID = -4293185642035773779L;
@SuppressWarnings("unchecked")
public void valueChange(ValueChangeEvent event)
{
item = (T) table.getValue() ;
if (null != item)
{
btnEditContent.setEnabled(true) ;
btnDeleteContent.setEnabled(true) ;
}
}
});
}
return table ;
}
This is one of those embarassing moments, when you realize you did something really stupid.
I'd copied some code and the getCompany() method was protected not public.
So issue solved, but programmer now about 1/4 inch tall and red faced.