JPAContainer Beans FieldGroup and TreeTable -- OH MY!

In my continuing expansion of a project I am working on – I now have need to show data in a tree table (because the data is, indeed, hierarchical) …

My main Entity – which I fetched via a JPAContainer (Hibernate flavor) – has an accessor to a set of Entities called Charges … (and one called Cases) …

Charges can be children of other Charges, and there is a nice property for that relationship … all good so far…

My question is this: given the fact I already have the set of Charges (via an accessor off the main Entity) available … how can I EASILY get this showing in a tree table?

Creating a new HierarchicalContainer from scratch and loading it “manually” seems tedious – as does creating a new “HierarchicalBeanItemContainer” … especially since JPAContainer / EntityHierarchicalContainer basically does what I want…

I guess what I would like to do is something simple like:


Set<Charges>  setOfCharges ;   // this is filled ... 
JPAContainer <Charges>  chargesContainer = new JPAContainer(Charges.class) ;
chargesContainer.setDataSource( setOfCharges );
chargesContainer.setParentProperty( "parentChargeID");

ANd then bind that to a TreeTable :slight_smile:

However, one can’t pre-fill in a JPAContainer as the above (that I can see) –

So what’s the best way to accomplish this?

TIA!

/Steve

Hi Steve,

You could create a JPAContainer for Charges and then add a filter to it that ensures that the back reference to the main entity is a certain value. See the
DepartmentSelector
in the JPAContainer address book demo, which does something similar. (The linked version is for Vaadin 7, but it should be fairly similar in Vaadin 6)

HTH,
/Jonatan