Directory

← Back

PreCreatedFieldsHelper

No more excuses to do data binding manually - build your form layouts as you wish!

Author

Rating

Popularity

<100

NOTE, this add-on was renamed to FormBinder. This add-on will no longer be updated.

This add-on contains a helper class and a custom form implementation to ease using pre created fields pattern. Customizing form layout and setting fields settings has never been easier. Forms can e.g. be designed with Vaadin Visual Editor and they can still take all advantages of the Form component.

WHAT IS "PRE CREATED FIELDS PATTERN"

Normally when using Vaadin forms, fields are created for item's properties on demand. The task of creating fields for properties is delegated to a FormFieldFactory. These fields are then added to the Form's layout and form binds properties automatically to them. This approach is usually fine and thanks to customizable FormFieldFactory and layout, form can be customized quite a lot.

In practice things may get rather messy and complex if the the layout becomes multilevel or it is e.g. designed with Vaadin Visual Editor. Lots of custom logic is needed to overridden attachField/detachField methods etc.

In pre created fields pattern responsibilities of field factory is narrowed. Instead of creating new fields for requested properties, its job is only to connect properties to existing fields (created manually by developer) in the form (or its layout).

With pre created fields pattern the Form also needs some minor changes: it must be modified to avoid attaching and detaching fields automatically as the developer has already attached them to their appropriate location in the layout. Form changes are practically replacing attachField and detachField implementations with empty methods.

WHAT DOES PreCreatedFieldsForm/PreCreatedFieldsHelper DO

Pre created fields pattern is rather simple to implement manually. The field factory however normally needs a considerable amount of boilerplate code to work. PreCreatedFieldsHelper can be used to avoid this boilerplate code by using simple naming convention and some java reflect magic.

Practically PreCreatedFieldsHelper is a FormFieldFactory that connects properties to corresponding fields from "target" classes (most often subclasses of form/layouts or composites built with Vaadin Visualdesigner). The connecting is done based on Fields name (java fieldname). The helper class can be used as is or behind the scenes by using PreCreatedFieldsForm.

Contributors (in addition to original author): Eduardo Frazão (annotation based field mapping)

Sample code

		// create an example pojo with some default content
		final MyExamplePojo myExamplePojo = new MyExamplePojo();
		myExamplePojo.setFirstName("Matti");
		myExamplePojo.setLastName("Meikäläinen");
		myExamplePojo.setBirthDate(new Date());
		myExamplePojo.setWeight(71);
		
		// create a form with MyExamplePojoView, which contains fields like
		// TextField firstNameField, lastNameField etc
		PreCreatedFieldsForm form = new PreCreatedFieldsForm(new MyExamplePojoView());

		// wrap pojo in a bean item and bind it to the form
		form.setItemDataSource(new BeanItem<MyExamplePojo>(myExamplePojo));

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

Added annotation based mapping support

Released
2011-09-19
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.0+
Browser
Browser Independent

PreCreatedFieldsHelper - Vaadin Add-on Directory

No more excuses to do data binding manually - build your form layouts as you wish! PreCreatedFieldsHelper - Vaadin Add-on Directory
NOTE, this add-on was renamed to FormBinder. This add-on will no longer be updated. This add-on contains a helper class and a custom form implementation to ease using pre created fields pattern. Customizing form layout and setting fields settings has never been easier. Forms can e.g. be designed with Vaadin Visual Editor and they can still take all advantages of the Form component. WHAT IS "PRE CREATED FIELDS PATTERN" Normally when using Vaadin forms, fields are created for item's properties on demand. The task of creating fields for properties is delegated to a FormFieldFactory. These fields are then added to the Form's layout and form binds properties automatically to them. This approach is usually fine and thanks to customizable FormFieldFactory and layout, form can be customized quite a lot. In practice things may get rather messy and complex if the the layout becomes multilevel or it is e.g. designed with Vaadin Visual Editor. Lots of custom logic is needed to overridden attachField/detachField methods etc. In pre created fields pattern responsibilities of field factory is narrowed. Instead of creating new fields for requested properties, its job is only to connect properties to existing fields (created manually by developer) in the form (or its layout). With pre created fields pattern the Form also needs some minor changes: it must be modified to avoid attaching and detaching fields automatically as the developer has already attached them to their appropriate location in the layout. Form changes are practically replacing attachField and detachField implementations with empty methods. WHAT DOES PreCreatedFieldsForm/PreCreatedFieldsHelper DO Pre created fields pattern is rather simple to implement manually. The field factory however normally needs a considerable amount of boilerplate code to work. PreCreatedFieldsHelper can be used to avoid this boilerplate code by using simple naming convention and some java reflect magic. Practically PreCreatedFieldsHelper is a FormFieldFactory that connects properties to corresponding fields from "target" classes (most often subclasses of form/layouts or composites built with Vaadin Visualdesigner). The connecting is done based on Fields name (java fieldname). The helper class can be used as is or behind the scenes by using PreCreatedFieldsForm. Contributors (in addition to original author): Eduardo Frazão (annotation based field mapping)
Online