Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

8.11. Validating a Wizard Form

Problem

You need to perform validations on a form shared across pages as part of a wizard-style interface.

Solution

Use the Validator's built-in support for wizards via the page attribute. Example 8-16 configures the Validator use of this attribute. Validations will be performed on fields where the page attribute value is less than or equal to the page property of the ActionForm.

Example 8-16. Use of the Validator page attribute

<form name="WizardForm">
    <field property="username" page="1"
            depends="required">
        <arg key="prompt.username"/>
    </field>
    <field property="password" page="2"
            depends="required">
        <arg key="prompt.password"/>
    </field>
    <field property="ssn" page="3"
            depends="required,mask">
        <arg key="prompt.ssn"/>
        <var>
            <var-name>mask</var-name>
            <var-value>^\d{3}-\d{2}-\d{4}$</var-value>
        </var>
    </field>
</form>

If the form used for the wizard uses the DynaValidatorForm (or one of its subclasses), add a form-property with the name of page. The property must be of type java.lang.Integer:

<form-bean name="WizardForm"
           type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="username" type="java.lang.String"/>
    <form-property name="password" type="java.lang.String"/>
    <form-property name="ssn" type="java.lang.String"/>
    <form-property name="page" type="java.lang.Integer"/>
</form-bean>

For conventional ActionForms that subclass ValidatorForm (or one of its subclasses), no changes are necessary. The ValidatorForm already provides a page property. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page