Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In the Coding Actions lesson, we validated the username and password input with a few lines of Java code. Of course, in a larger application, over time, even these few lines of code can become a maintiance budenmaintenance burden.

Happily, the framework provides a validation framework that can confirm validate input "behind the scenes".

The Code

Like the mappings, validation is Validation can be described through an XML document, or using annotations. The XML document is named after the Action being validated with a "-validation" suffix. Since we would like to validate the Login Action class, our document is named Logon-validation.xml.

Code Block
formatXML
titleLogin-validation.xml
borderStylesolid
<!DOCTYPE validators PUBLIC 
"-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <message>Username is required</message>
        </field-validator>
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message>Password is required</message>
        </field-validator>
    </field>
</validators>

...