JPAContainerItem and BeanFieldGroup in Vaadin 7

Hi all,

I have a table with JPAContainer binding. I want to edit an item from the table (JPAContainerItem) in a BeanFieldGroup. Since a BeanFieldGroup takes only BeanItems, I get a ClassCastException.

java.lang.ClassCastException: com.vaadin.addon.jpacontainer.JPAContainerItem cannot be cast to com.vaadin.data.util.BeanItem

thank you

Hi Johannes,

You shouldn’t use a BeanFieldGroup in this case, as it would require you to write custom mapping code between a BeanItem and JPAContainerItem for the JPAContainer to know what happens to the properties in the item. This is required for JPAContainer to be able to store the item correctly after being edited.

So you should use a plain FieldGroup instead of the BeanFieldGroup and if there was some specific reason as to why you wanted to use BeanFieldGroup (I can’t think of any) then you need to extend FieldGroup into a class of your own where you add this functionality.

HTH,
/Jonatan

Can you post some code about this? I’m having similar problems, but i haven’t find any examples.

Currently, I am writing a custom form based on a BeanFieldGroup. The main object has a list of selectable objects inside, but I haven’t found a “elegant” way of doing it. What I do is create a ListSelect which is outside the FieldGroup, and after the commit, manually add the selected items to the final bean.

Thanks

I’m also looking for examples using JPAContainerItem and FieldGroup.

Hi guys,

I just added
a small example
of one way of using JPAContainer together with FieldGroup to the JPAContainer integration test project.

HTH,
/Jonatan