Validator plugin for Struts 1.1

farrightΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 11 μήνες)

540 εμφανίσεις

Validator


A plugin for struts 1.1


Provides a fairly complete list of pre
-
written validations for forms


Extensible to write your own validations


By default it does server
-
side validation
but it can also handle client side
javascript


Can handle

wizard


web pages

Basic idea


In an external XML file..


You declare a form


Then you declare a field


Then you state which validations to
apply


Then it all works

How to implement


Your ActionForms now extend
ValidatorForm


You need to put entries in validation.xml


Declare the formbean


Declare the field


Declare the validations


Enter the error message in
application.properties

Types of validation available


Required **


Requiredif


Minlength


Maxlength


Mask


Byte


Short


Integer**



Long


Float


Double


Date


intRange


floatRange


Credit card


Email**


Abilities we won

t cover


Enabling javascript


Writing your own custom validator


Multi
-
page forms (wizards)


Multi
-
lingual error messages


Using commons
-
validator outside of
struts

Decent resources


http://jakarta.apache.org/struts/userGuide/dev_
validator.html

(talks about javascript,
Internationalization, and custom validators


http://jakarta.apache.org/struts/userGuide/build
ing_view.html

(very basic)


http://www.manning.com/husted/chap12.pdf

(sample chapter from struts in action)


http://javaboutique.internet.com/resources/boo
ks/strutsAction/struts6_1.html

(good for how to
use each type of validator)


The best is to take the example webapp apart


Validator Lab


We are going to make a new form
that gathers information from the
user


New ValidatorForm


New Action


New pieces to application.properties


New JSP pages


Modify struts
-
config

Quick intro to Ant


Basically an xml file that species what to do
during the process of

making


an application


Everything is in a file called build.xml


Can do almost anything you want


Checkout from VCS


Compile your entire project


Start and stop tomcat


Make a deploy file


Filter and replace in your files


SCP or SFTP between machines


Validate your xml


Many many more

How to use ant



You define properties


You define tasks


They can depend on other tasks


They can be executed by themselves


Then you run it


The default task


Specific task


In netbeans, you can just press f6 while
the build.xml is highlighted


Should we look at it together?