Directory

← Back

FieldBinder Addon

FieldBinder Add-on

Author

Contributors

Rating

An advanced FieldGroup implementation with support for automated generation of Master/Detail forms.

The FieldBinder add-on is an advanced FieldGroup implementation.

Features:

  • A FieldBinder<T> binds to a Java Bean, like a BeanFieldGroup
  • Managed Fields (built using build()) can be always bind()'ed and unbind()'ed; the FieldBinder will always keep track of them
  • A FieldBinder can build() and bind() a component that displays a bean property even when it is a List
  • A FieldBinder can be bound to a Container. The DataNavigation interface provides commands to move an internal pointer to the next, previous, first and last Item in the Container (the Container must implement Container.Ordered: most Container implementations do, since it is required by Table)
  • The DataNavigation interface provides commands to scan through a dataset and retrieving the Item that it points to.
  • The DataNavigation interface provides standard behavior for performing CRUD operations (and, experimentally, lookup operations), which can be extended through a regular, Vaadin-style listener mechanism
  • FieldBinder comes with standard built-in CRUD for the ListContainer and the Lazy Mongo Container. The ListContainer should already cover most Java Bean use-cases, including JPA. Support for the Vaadin's official JPAContainer is under development.
  • The ButtonBar component (and its relatives, NavButtonBar, CrudButtonBar, FindButtonBar) may be bound to a DataNavigation and automatically generate buttons for user interactions (automatic shortcut key bindings will come soon!)
  • ButtonBars are i18n compliant through the standard Java ResourceBundle mechanism
  • The ListTable and BeanTable wrappers augment Vaadin's regular Table with default behavior for basic CRUD.

Sample code

public class ShortTutorial extends UI {
  
  // CONTAINER
  
  // initialize an empty container
  final FilterableListContainer<Person> container = 
                                    new FilterableListContainer<Person>(Person.class);
  
  // FIELD BINDER 
  // initialize the FieldBinder for the given container
  final FieldBinder<Person> binder = new FieldBinder<Person>(Person.class, container);

  // initialize the layout, building the fields at the same time
  final VerticalLayout mainLayout = new VerticalLayout(

      // auto-generates a button bar with the appropriate behavior
      // for the underlying FilterableListContainer
      new ButtonBar(binder.getNavigation().withDefaultBehavior()),

      new FormLayout(
          // automatically generate a Field from the property type
          binder.build("firstName"),
          binder.build("lastName"),
          binder.build("birthDate"),
          binder.build("age"),
          
          // optional: display the index of the currentItem in the container
          new NavigationLabel(binder.getNavigation()) 

      ),

      // initialize the addressList field with a built-in button bar
      binder.buildListOf(Address.class, "addressList").withDefaultEditorBar()

  );


  @Override
  protected void init(VaadinRequest request) {
    setContent(mainLayout);
  }

}

class MyController implements ItemEdit.Listener, ItemCreate.Listener, BeforeCommit.Listener {

  @Override
  public void itemEdit(ItemEdit.Event event) {
    age.setReadOnly(true);
  }

  @Override
  public void itemCreate(ItemCreate.Event event) {
    age.setReadOnly(true);
  }

  ...
  @Override
  public void beforeCommit(BeforeCommit.Event event) {
    // e.g., using JodaTime:
    DateTime birthDateValue = new DateTime(birthDate.getValue());
    int ageValue = Years.yearsBetween(birthDateValue, DateTime.now()).getYears();

    age.setReadOnly(false);
    age.setConvertedValue(ageValue);
    age.setReadOnly(true);
      
  }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Many bug fixes and cleanup in internal interfaces

Released
2015-03-17
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.3+
Vaadin 7.0+ in 1.3
Browser
N/A
Online