Updating FormLayout from FieldGroup

Warning: Newb
I have a FieldGroup, Table and FormLayout. The Table is successfully being populated using a JPAContainer. I believe the Table valueChange event is successfully creating a BeanItem. However, when I set the setItemDataSource value on the FieldGroup the FormLayout is not updated. The relevant code snippets are:

private FieldGroup binder = new FieldGroup();

editPerson = new FormLayout();
TextField firstName = new TextField(“First Name”);
TextField lastName = new TextField(“Last Name”);

personTable.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 7692735275376898339L;
public void valueChange(ValueChangeEvent event) {
Long id = (Long) event.getProperty().getValue();
person = (User) persons.getItem(id).getEntity();
Notification.show(person.getFirstName()); // Verifying that person is a valid object
BeanItem item = new BeanItem(person);

Any advice would be greatly appreciated.

Kind regards


If you call binder.bindMemberFields(editPerson); you need to use @PropertyId on the ui fields you want to bind. But this implies to extend FormLayout and define the fields as members in the class. Have a look at the javadoc of that method.

Instead you can bind each field individually, using one of the buildAndBind methods.

Also, you may read this: https://vaadin.com/book/-/page/datamodel.itembinding.html to get more insights on how FieldGroup works.

Hi Bogdan
Thanks for the pointer. I have now got it :slight_smile: Things are working as they should.
Help appreciated.

Hi Sean,

You’re welcome! Please let us know anytime when you have problems. I hope you’ll enjoy Vaadin!

All the best,