Forms add-on

Forms is a new add-on that aims to provide the developer with easier ways to create Vaadin Form objects and more control over the layout of the form.

Currently, this add-on only provides a single implementation named GridForm. This object is a Vaadin Form using a GridLayout to lay out the components. While a Vaadin Form can use a GridLayout already, there is no support for actually telling the form where to place the components nor is there the ability to have components span multiple rows and columns. GridForm attempts to solve this problem.

Inspiration for this add-on comes from the excellent JGoodies Forms library. The goal of this add-on is to provide the developer means for easily creating elegant forms and components using methods crafted by JGoodies Forms.

How do you configure the use of a Select field for one of the properties?

There are two ways to do this:

  1. Set a custom FormFieldFactory on the form
  2. User the
    public Select replaceWithSelect(Object propertyId, Object[] values, Object[]
    descriptions)
    method in the Form class

Example of method 1:


enum Fruit { APPLE, ORANGE, GRAPES, PEAR }

...

class MyFieldFactory extends DefaultFieldFactory {
    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {

        if (propertyId.equals("fruit")) {
            List<String> fruits = new ArrayList<String>(Fruit.values().length);
            for (Fruit fruit : Fruit.values())
                fruits.add(fruit.name());
            return new Select("Fruit", fruits);
        }
        return super.createField(item, propertyId, uiContext);
    }
}

...

form.setFormFieldFactory(new MyFieldFactory();

To be a bit more specific, there’s a method attachField(Object propertyId, Field field) (see description
here
), which controls the process of adding the components to the Form. Add-on is a nice wrapper around its functionality, but the desired result can be gained by simply overriding the method.

kind regards,
sasha