2

When binding fields to a bean there are two ways:

  1. Use a FieldGroup and wrap the bean in a BeanItem:

    final FieldGroup fieldGroup = new FieldGroup(new BeanItem<DataBean>(dataBean));
    
  2. Use a BeanFieldGroup, in this case the bean will also be wrapped into a BeanItemunder the hoods:

    final BeanFieldGroup<DataBean> beanBinder = new BeanFieldGroup<>(DataBean.class);
    beanBinder.setItemDataSource(dataBean);
    

IMHO using a FieldGroup is actually simpler, is there any advantage in using a BeanFieldGroup?

Roland
  • 7,525
  • 13
  • 61
  • 124

1 Answers1

2

BeanFielGroup is an extension of FieldGroup, In addition to the properties of FieldGroup it also has support for

  • Java Bean Validation API 1.0 (JSR-303)
  • Handles Nested Properties.
  • Certain Helper methods to add various fields.

Based on your use case you can prefer either of it. If you are managing the Form/layout via Pojo's I would suggest you should use BeanFieldGroup instead of FieldGroup and if you have loosely coupled properties, I would suggest FieldGroup over BeanFieldGroup

Patton
  • 2,002
  • 3
  • 25
  • 36