Can't bind with BeanFieldGroup

I tried to bind a bean with constraints annotation with the field of a FormLayout and use commit to handle validations.

I have:

  • A bean (Person.class) with only property “name” with @NotNull and @UIScoped
  • A FormLayout with a TextField “name” and a Button
  • In my UI a do the bind.

[font=courier new]
public class MyUI extends UI {
private Person person;
private LoginLayout layout;
private BeanFieldGroup binder;

protected void init(VaadinRequest vaadinRequest) {
    layout = new LoginLayout();
    binder = new BeanFieldGroup<>(Person.class);
        } catch (Exception ce){
  , Notification.Type.ERROR_MESSAGE);


The commit doesn´t throw any exception.
Even if a initialized the property name = “user” the textfield remains blank. It is like BeanFieldGropu doesn’t bind any bean with any textfield.



try putting bindMemberFields before setItemDataSource, should work.


Thanks, Sergey
But it doesn’t work.

It’s strange.
I did it in that order beacuse it is done so in the book-vaadin-examples.

The difference is that in the book, the layout is created and bind the member fields with buildAndBind
and i bind with bindMemberFields using an instance of formLayout.

I tried to validate the empty textField name with three differents manners:

  • adding setRequired to the textField name.
  • adding tha annotation @NotNull in the property name of the bean.
  • addind a validator NotNullValidation in the textField.

The two first work but the last doesn’t.

I use the method commit of the BeanFieldGroup.
I was wonder if commit’s method validate the fields (i think so) but in my case it doesn’t throw CommitException with the validator.

This is my formLayout class.

public class MainLayout extends FormLayout{
    private TextField name;
    private Button valida;

    public MainLayout(){
        name = new TextField("Nombre: ");
        name.addValidator(new NullValidator("Debes introducir un nombre", true));
        addComponents(name, valida);

The listener of the button valida is in a View

... layout.getValida().addClickListener(e-> { try{ layout.visible(); //set the validation visible to true binder.commit(); //binder is the instance of BeanFieldGroup } catch(CommitException ce){, Notification.Type.WARNING_MESSAGE); } });
Why commit doesn’t throw the Exception when the TextField name has a NullValidator?

Jose A.


I Found in the API the response.
i was misunderstood the constructor of NullValidator.

NullValidatorpublic NullValidator(java.lang.String errorMessage, boolean onlyNullAllowed)Creates a new NullValidator.

errorMessage - the error message to display on invalidation.
onlyNullAllowed - Are only nulls allowed?

It must be

name.addValidator(new NullValidator("Debes introducir un nombre", false)); It’s a bit confused NullValidator to validate not null fields!!! if you put the second param true.