CollectionContainer - bind arrays and collections

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.

Now 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 examples:
http://sami.virtuallypreinstalled.com/collectioncontainer/

Download from Vaadin Directory:
http://vaadin.com/directory#addon/collectioncontainer

Hi all,

I was working on a small analysis project and along the way I found a nifty way of displaying CSV (comma separated values) in
Vaadin Table
.

To do this you need
OpenCSV
and the
CollectionContainer
add-on.

But with these it becomes quite easy:

// Read using OpenCSV
CSVReader r = new CSVReader(new FileReader(file));
List<Object[]> rows = r.readAll();

// Extract column captions
String[] columnHeaders = (String[]
) rows.get(0);
rows.remove(0); 

// Bind to table
CollectionContainer ds = CollectionContainer.fromPrimitives(rows, -1);
table.setContainerDataSource(ds);
table.setColumnHeaders(columnHeaders);


Disclaimer:
As you can see here, the data is read fully into a List (which does not scale to large amounts) and no error checking is present (left it out for readability).

Anyway, this works very well for my case of “typical” amount of data (i.e. ~1000 rows, ~10 columns).

Any plans to migrate this to Vaadin 7? If not, I might have a go at it.

Thanks,
Frans