Docsity

Using ActionForm with Validator in Struts: A Comprehensive Guide, Slides of Java Programming

Partial preview of the text

Download Using ActionForm with Validator in Struts: A Comprehensive Guide and more Slides Java Programming in PDF only on Docsity!

Element: child

element

...

...

 Set parameters that a field element may need to pass to

one of its validation rules such as minimum and

miximum values in a range validation

 Referenced by elements using ${var:var-name}

syntax

Validation Framework:

How do you use

ActionForm with

Validator?

Choices You have

 Standard ActionForms or Dynamic ActionForms?

(rehash)

 If you want to specify ActionForms declaratively, use

dynamic ActionForms

 xValidatorActionForm or xValidatorForm?

 Use xValidatorActionForm if you want more fine-grained

control over which validation rules are executed

 In general, xValidatorForm should be sufficient

Validation Framework: struts-example Sample code

validation-rules.xml: Built-in

“required” validation rule

**

validation-rules.xml: Built-in

“minlength” validation rule

**

ApplicationResources.Properties

Standard error messages for validator framework checks

errors.required={ 0 } is required. errors.minlength={ 0 } cannot be less than { 1 } characters. errors.maxlength={ 0 } cannot be greater than { 2 } characters. errors.invalid={ 0 } is invalid. errors.byte={ 0 } must be an byte. errors.short={ 0 } must be an short. errors.integer={ 0 } must be an integer. errors.long={ 0 } must be an long. errors.float={ 0 } must be an float. errors.double={ 0 } must be an double. errors.date={ 0 } is not a date. errors.range={ 0 } is not in the range { 1 } through { 2 }. errors.creditcard={ 0 } is not a valid credit card number. errors.email={ 0 } is an invalid e-mail address.

LogonForm Validation: “required”

LogonForm Validation: “maxlength”

Validation Framework:

Examples

Validating zipCode field with

“validwhen” validator

test

(((city != null) and (state != null)) or (this != null))

Validating Field Equality in Struts

1.2 using “validwhen”

test (this == password)

JavaScript Support in Validator

Framework

 The Validator framework is also capable of generating

JavaScript for your Struts application using the same

framework as for server-side validation

 By using a set of JSP custom tags designed specifically for

this purpose