 |
Struts integration
Easy Wizard integrates with Struts by means of Struts Dialogs library. Struts Dialogs is a collection of action classes based on DispatchAction. Struts Dialogs brings Struts user interface closer to modern event-driven frameworks like JSF.
To integrate wizard with Struts you need to define wizard steps, transitions and wizard controller; see previous chapters on how to do this. Then, you need to decide will your wizard accept strong-typed data or only string-typed data.
If you decide to create a wizard which has strong-typed getters and setters, you would need to do the conversion yourself, either by using a conversion tool, or manually by using getters and setters of Struts form bean.
If you decide to have a wizard with string-typed setters, then you can simply make a wizard a field of a form bean, and access wizard fields as nested properties of a form bean.
Despite the choice, you still need to deliver incorrect input data to the wizard controller, and to perform validation inside the wizard controller. The reasons are:
- when wizard renders a view, it displays current wizard data, even if the input was incorrect;
- error messages are generated during validation process, and should be uniform for different frameworks;
- most important, that validation affects selection of next wizard step.
On the other hand, you can use standard tools like Commons Validator in your wizard.
Using string setters and getters
Using strings for input and output is easy, though it may not integrate well with your current approach for input validation.
- Define all fields of the wizard with string getters and setters.
- Define Struts action class, which extends WizardAction or uses WizardAction directly.
- Define a Struts action form with session scope, extenging WizardForm.
- Aggregate wizard controller in a form bean, that is, make wizard controller a field of the form bean.
- Dispatch client events to action class, and from action class to the form bean.
When using Struts Dialogs, Action class together with action form perform functions of Wizard Manager for Struts. Action class functions as an event dispatcher, and the actual processing is done within form bean. This contradicts with traditional usage of Struts actions and forms, but works better with dialogs and wizards.
The reason for having a form bean as main processing class, is because wizard is a stateful object. The state of a wizard is stored on server. The easiest way to achieve this is to use objects which session scope. Struts already provides such an object, a form bean. This is even more convenient, since form bean fields are automatically populated with input data.
By declaring form bean with session scope and by aggregating wizard controller in form bean it is possible to maintain the stateful object, updateable by client.
Struts Wizard Example
See example for WizardAction from
Struts Dialogs library.
|