Building the Bike Editor Forms

So far, the application looks good, but it doesn't do too much that's useful. You still need to create a BikeForm to display in a titled dialog, allowing the editing of properties on an existing bike. The same form will need to be used to add a new bike to store inventory.

In general the forms framework, with the data binding and validation framework, are three of the fundamental strengths of the Spring Rich Client Project.

How do I do that?

To create your bike form, you'll first define the declarative validation rules for the Bike class. These rules will be defined independent of any presentation code, so they can easily be reused in different environments.

After that, you'll see how to implement the BikeForm itself, and how the framework auto-binds form controls to backing domain object properties for you, with as-you-type validation.

Finally, you'll review the BikeForm integration with the PropertiesCommandExecutor defined in the previous lab (for editing an existing Bike), and see how to reuse the BikeForm in a NewBikeWizard in order to add new bikes to store inventory.

Validation

When a user edits or adds a bike, you want the framework to validate any new data. Furthermore, you want any valida tion errors to be clearly communicated to the user. Lastly, you want the framework to prevent forms that contain validation errors from being submitted.

To hook in validation rules, add the following bean to your root application context:

<beans>

    <bean id="rulesSource ...

Get Spring: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.