Creating BeanItemContainer from ArrayList

I sure hope, this does not sound too stupid. I have an ArryList which I want to display in a Vaadin Table. So my thought was to build a BeanItemContainer formed out of the items in the List and create the Table from the BeanItemContainer. There seems to be no mechanisim to do this so my approach would be to iterate over the ArrayList putting every Object in the BeanItemContainer. Can this be done without any drawback I do not see at the moment or are there any ‘best practices’ on doing this?


(for simple object arrays) or
(for bean arrays) perhaps what you’re looking for?

In Vaadin 6.5, there will be an alternative implementation (currently called BeanContainer) which supports explicitly given identifiers or getting the identifiers e.g. from a property of the beans.

If you want to use BeanItemContainer so that the bean instances are their own item identifiers, the method addAll(Collection) in BIC is public in Vaadin 6.5. When using an older Vaadin version, give the items to the container constructor as a collection, or simply add the items in a loop (causing some filtering overhead if adding a large number of items). When moving to Vaadin 6.5, you should add the type parameter to the constructor call taking a collection.

If you don’t need any features of BeanItemContainer with respect to looking inside the beans etc., the (read-only?) containers mentioned by Marko are probably a good starting point; also IndexedContainer might or might not make sense depending on your beans.

I apologize for taking so long to respond. The two solutions stated look good and besides that it sounds nice how the BeanItemContainer will change in the future. Indeed at the moment copying in a loop seams to be the best solution for me. Thanks to both of you.