How can I avoid validating a form before
data is entered?
The simplest way is to have two actions. The first one has the job of
setting the form data, i.e. a blank registration screen. The second
action in our writes the registration data to the database. Struts would
take care of invoking the validation and returning the user to the
correct screen if validation was not complete.
The EditRegistration action in the struts example application
< action path="/editRegistration">
<forward name="success path="/registration.jsp"/>
When the /editRegistration action is invoked, a registrationForm is
created and added to the request, but its validate method is not called.
The default value of the validate attribute is true, so if you do not
want an action to trigger form validation, you need to remember to add
this attribute and set it to false.
How can I create a wizard workflow?
The basic idea is a series of actions with next, back, cancel and finish
actions with a common bean. Using a LookupDispatchAction is reccomended
as it fits the design pattern well and can be internationalized easily.
Since the bean is shared, each choice made will add data to the wizards
base of information. A sample of struts-config.xml follows:
<!-- the first screen of the wizard (next action only available) -->
<!-- no validation, since the finish action is not available -->
<!-- the second screen of the wizard (back, next and finish) -->
<!-- since finish action is available, bean should validated, note
validation should not necessarily validate if back action requested, you
might delay validation or do conditional validation -->
<!-- the last screen of the wizard (back, finish and cancel only) -->
The pieces of the wizard are as follows:
forms.MyWizard.java - the form bean holding the information required
actions.MyWizard.java - the actions of the wizard, note the use of
LookupDispatchAction allows for one action class with several methods.
All the real work will be done in the 'finish' method.
mywizard[x].jsp - the data collection jsp's
mywizarddone.jsp - the 'success' page
mywizardcancel.jsp - the 'cancel' page
What's the best way to deal with migrating a large application from
Struts to JSF? Is there any tool support that can help?
Answer: This is a complicated task depending on your Struts application.
Because the two frameworks have different goals, there are some
challenges. Migrate your response pages first. Keep the Struts
controller and place and forward to JSF pages. Then you can configure
Struts forwards to go through the Faces servlet. Consider looking at the
Struts-Faces framework from Apache. See the framework chapter in JSF in