CollectionContainer
The simple way of binding collections and arrays to the data-aware Vaadin components like the Table and the Select.
Sometimes you only have a list or array of objects you'd like to bind to a ListSelect or a Table and forget about the fancy Container features like lazy loading or automatic updates.
Creating a Container from a list or array of beans, string, integers is easy. And you can configure the CollectionContainer to have different type of ids. CollectionContainer is a read-only Container implementation suitable best for small amounts of data, backed simply by a collection storage. Here are some samples:
Use the object itself as id (like in the stock BeanItemContainer): select.setContainerDataSource(CollectionContainer.fromBeans(myBeans)); select.setContainerDataSource(CollectionContainer.fromPrimitives(new String[]{"One","Two","Three"}));
Index based id that allows duplicate objects: select.setContainerDataSource(CollectionContainer.fromBeans(myBeans,true)); select.setContainerDataSource(CollectionContainer.fromPrimitives(new String[]{"One","Two","Three","One"},true));
A two dimensional array to a table using: String[][] array = new String[][] { new String[]{"One","Two"}, new String[] {"Three","Four"}}; table.setContainerDataSource(CollectionContainer.fromPrimitives(array));
And you can even use a bean property as the item id: select.setContainerDataSource(CollectionContainer.fromBeans(myBeans,"idField"));
This is an experimental component, but it has been successfully utilized in many projects already. It only supports reading, not writing or adding items to container.
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Fixed null item sorting. Thanks tnsan79 for the patch.
- Released
- 2010-12-08
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 6.0+
- Vaadin 7.0+
- Browser
- Browser Independent
CollectionContainer - Vaadin Add-on Directory
The simple way of binding collections and arrays to the data-aware Vaadin components like the Table and the Select.Source Code
Discussion Forum
Author Homepage
Issue Tracker
CollectionContainer version 0.9.3
Fixed null item sorting. Thanks tnsan79 for the patch.