BeanItemContainer - no constructor to limit the property names.

I was so happy to discover

BeanItem(Object bean, String propertyIds)

constructor.

As many people, I use Hibernate, and my beans have many links to other beans (through lazy collections eventually).
I do not want BeanItem to touch all these properties and triggers SQL traffic (or an exception if the hibernate session is closed, which is the case if my bean is from another HttpRequest…).

Limiting in the ui is not enough. i.e. forms Form.setVisibleItemProperties(Collection visibleProperties)
It does not prevent the BeanItem to touch the other properties. So the
BeanItem(Object bean, String propertyIds) constructor is very necessary in a real world hibernate application to my taste.


But
… (here comes my question).

The BeanItemContainer class has no such constructor.
The BeanItemContainer instantiates BeanItem without limitation on the property list.

Question: is there a way that I missed to make BeanItemContainer limiting its model to a given list of properties (except rewriting BeanItemContainer myself :wink: ?

Many thanks.
John.

I don’t think the BeanItemContainer by itself should not touch any values from the bean, when does this happen? Touching the property classes themselves is harmless, as long as the getter in the bean is not invoked (using property.getValue()). If you use it as a datasource in e.g. a Table the Table should only request values for the properties related to the visible columns. So for instance the following code

  
BeanItemContainer<MyData> bic = new BeanItemContainer<MyData>(MyData.class);
bic.addBean(new MyData());
bic.addBean(new MyData());

Table table = new Table("", bic);
table.setVisibleColumns(new String[] { "a" });

[MyData class with getters/setters for a and b omitted]

never calls the MyData.getB() method even though the BeanItemContainer has not been limited in any way.

Indeed. I was still in the mind of forms (which touche the properties before any chance to call the setVisible…).
Thank you Artur.

Hi,

Regarding the above code snippet, visible columns will reset if you change containers again, even to the same old container:

 BeanItemContainer<MyData> bic = new BeanItemContainer<MyData>(MyData.class);
 bic.addBean(new MyData());
 bic.addBean(new MyData());
 
 Table table = new Table("", bic);
 table.setVisibleColumns(new String[] { "a" });
 table.setContainerDataSource(bic)

Will result in both a and b showing. I won’t file a ticket on this, since I don’t know if it’s a bug or just a feature. But it took me damn long to find out the hard way…