Form field binding

Hello!

I need to implement the following feature: We have two classes A and B with the relationship A has B.
The form shows only the fields from class A. And class B is treated as a TextField.
We need to show the fields from class B on the form.
It can be implemented using 2 forms for each of these classes. But this solution doesn’t suite well.

Are there any alternative ways to implement this?

If you use BeanItemContainer, BeanContainer, or JPAContainer to bind the classes, they allow nested bean properties as explained
here
and demonstrated
here
. The BeanItem does not support that.

Thank you for reply but how can I use BeanItemContainer, BeanContainer, or JPAContainer with vaadin Form class?

Well, containers are usually used with components such as Table where you have a number of items. In master-detail views you have a Table to display a list of items and a Form to edit a selected one. Your case would be like a master-detail view, but without the master.

So, if you really have just one of such objects, put it in one of those containers and then get it out as an item which you can use in the Form.

Or with a perhaps simpler approach, use a wrapper bean that contains the bean A and then delegates getters and setters to that as well as to the B bean inside it. Or just extend A and add the getter and setter delegations.

…or rather, if you only have one such object, just wrap it in a BeanItem and add the nested method properties you are interested in directly to the BeanItem, and the rest should happen automatically. You do not necessarily need a container for this.

Thanks Henri, I added
a section about this
in the Book as well as
an example
.