Using the Apache Struts Validator Framework: Configuration and Validation Rules, Slides of Java Programming

Instructions on how to use the apache struts validator framework, including configuring the validator plug-in, creating validation.xml and validation-rules.xml files, and setting up action forms for validation. It covers built-in validation rules such as required, minlength, maxlength, and mask, and explains how to use them in your application.

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
Things to do in order to use
Validator framework
1)Configure Validator Plug-in
2)Configure validation.xml file (and validation-rules.xml
file)
3)Extend Validator ActionForms or Dynamic
ActionForms
4)Set validate=”true” on Action Mappings
5)Include the <html:javascript> tag for client side
validation in the form's JSP page
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Using the Apache Struts Validator Framework: Configuration and Validation Rules and more Slides Java Programming in PDF only on Docsity!

Things to do in order to use

Validator framework

1)Configure Validator Plug-in

2)Configure validation.xml file (and validation-rules.xml

file)

3)Extend Validator ActionForms or Dynamic

ActionForms

4)Set validate=”true” on Action Mappings

5)Include the tag for client side

validation in the form's JSP page

How to Configure Validator Plug-in

 Validator Plug-in should be configured in the Struts

configuration file

 Just add the following element

Validation Framework:

validation-rules.xml

Built-in Validation Rules

 required

 requiredif

 deprecated in Struts 1.

 use validwhen instead

 validwhen

 available from Struts 1.

 relies on user-specified test expression that include

references to other fields, field values, and local relationships

 minlength

 maxlength

validation-rules.xml: Built-in

“required” validation rule

validation-rules.xml: Built-in

“minlength” validation rule

**

Built-in Error Messages From

Validator Framework

Built-in error messages for validator framework checks

You have to add the following to your application's resource bundle

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.

Validation Framework:

validation.xml

validation.xml: logonForm (from

struts-examples sample code)

maxlength
16
minlength
3

validation.xml: registrationForm (from

struts-examples sample code)

**

**

** **

struts-config.xml: logonForm (from

struts-examples sample code)

Element

 Corresponds to a property in an ActionForm

 Attributes

 property: name of a property (in an ActionForm) that is to

be validated

 depends: comma-delimited list of validation rules to apply

against this field

 All validation rules have to succeed

Element: child

element

 Are used to pass additional values to the message

 is the 1 st^ replacement and is the 2 nd

replacement, and so on