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

An in-depth explanation of how to use actionform with validator in the apache struts framework. It covers the differences between standard and dynamic actionforms, and the use cases for xvalidatoractionform and xvalidatorform. The document also includes sample code and configuration files for reference.

Typology: Slides

2011/2012

Uploaded on 08/09/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
<field ...> Element: <var ...> child
element
<var>
<var-name>...</var-name>
<var-value>...</var-value>
</var>
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 <argx> elements using ${var:var-name}
syntax
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

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