Table with nested property - define method name?

Hi,

is it also somehow possible to define a method name exactly when using nested properties to show in a table?
Or does it always have to be a bean getter()?

I tried the following:


class DataBase {
	List<Person> persons;
}

table.setContainerDataSource(new BeanItemContainer<DataBase>(DataBase.class));
table.setVisibleColumns(new String[]{"persons.size"});
table.setColumnHeaders(new String[]{"person list size"});

This does of course not work, as .size() is not a bean and vaadin is looking for a getSize() method.

I know I can rewrite the bean class as follows to work around this:


class DataBase {
	List<Person> persons;
	public int getPersonSize() {
		return persons.size();
	}
}

But it would be nice if I could directly tell vaadin to use the person.size() method to display in the table, without having to introduce a read-only property.
Is that possible?

Hi,

As the BeanItem name suggests, it uses the JavaBean metadata to access the nested properties. JavaBeans must conform to either getXXX or isXXX for retrieveing value it’s part of the spec (See
the official documents
).

java.util.List is not a JavaBean, according to that spec.

I imagine if you created an appropriate BeanInfo class, you could probably map “.size” to “size()”[1]

  • but that’s probably alot of work compared to simply adding the getPersonsSize().

So, without using a custom property (either on the item - see
my example in your other thread!
- or on the bean), no, it is not possible.

Cheers,

Charles.

[1]

You might be able to create a java.util.ListBeanInfo, extending SimpleBeanInfo, and override getPropertyDescriptors to create a read-only property for “size”.

Thanks, yes I know as discussed in the other thread that I can create custom properties. I just wanted to know if non-bean methods can be forced to be looked up in a table. So, as your clear answer is “NO”, my question is resolved.