VisualBuilder
  Home > Jsp > Tutorials > Introduction to Standard Validator-Rules.xml - Struts Tutorial
Tell a friend
Link to us
Total Members
      Members: 84661
     
Sitemap Forum Chat
Home
Struts Tutorial Home
1 . What is Struts?
2 . Why do we need Struts?
3 . Advantages of Struts
4 . Setting up Eclipse for Web Development
5 . Registration Case Study
6 . Setting up Struts project in Eclipse
7 . Creating an ODBC Data source
8 . Configuring Application Server
9 . Struts Configuration
10 . Writing the User class
11 . ResourceManager
12 . Writing the Struts Business Component
13 . Creating the Action Class
14 . Adding ActionForward
15 . Deploy the Struts Application
16 . Adding the Form bean
17 . Configuring Form Bean in struts-config.xml
18 . Using Struts Tag Libraries
19 . Listing all Users - Struts Iterator Looping
20 . Add User Action - New Struts Action Class
21 . Add User View
22 . Validating Struts Form Bean
23 . Review of the Struts Tutorial
24 . Introduction
25 . DispatchAction
26 . DispatchAction Example Continued...
27 . Introduction to DynaActionForm
28 . DynaActionForm Example Continued...
29 . Struts solution to Duplicate Form Submission (Token mechanism)
30 . Introduction to Validation framework
31 . Example Continued Validation Framework.
32 . Client Side Validation
33 . Introduction to Standard Validator-Rules.xml
34 . Creating custom Valdator rules
35 . Extending the Validator Rules with the inherited SubForm Classes.-2
36 . Internationalization in struts application
37 . Exception Handling in Struts
38 . Creating Custom Exception Handlers in Struts-1
39 . Creating Custom Exception Handlers in Struts.-2
40 . Creating Plugin for the Struts Application. -1
41 . Creating Plugin for the Struts Application. -2
42 . WildCard Character mapping for the Actions-1.
43 . WildCard Character mapping for the Actions-2.
44 . WildCard Character mapping for the Actions-3.
45 . Uploading the Files to Server Using Struts-1
46 . Uploading the Files to Server Using Struts-2
47 . Introduction to Modules in Struts Application
48 . Modules Example-1
49 . Modules Example-2
50 . Customizing the ActionServlet Class for the application-1.
51 . Customizing the ActionServlet Class for the application-2.
52 . Customizing the ActionServlet Class for the application-3.
53 . Customizing the ActionServlet Class for the application-3.
54 . Customizing RequestProcessor Class for the application-1.
55 . Customizing RequestProcessor Class for the application.-2
56 . ComposableRequestProcessor in Struts 1.3
57 . Adding New Command Objects in Struts CoR Pattern
58 . Security in Struts
59 . Example for the Application Managed Security-1
60 . Example for the Application Managed Security-2
 
 
JSP Home
JSP Members (18709)
JSP Member Articles ( 11 )
JSP Discussion (71)
JSP Q & A ( 87 )
- JSP Ask Question
- JSP Questions
- JSP Unanswered Questions
JSP Resources
JSP Source Code (172)
JSP Articles (34)
JSP Blogs (333)
JSP Jobs (0)
JSP Components (10)
JSP Books (9)
JSP Websites (13)
JSP News (12)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Jsp struts Tutorial
 Introduction to Standard Validator-Rules.xml
  << Prev: Client Side Validation Next: Creating custom Valdator rules >>

The Inbuilt validation in the Validator-Rules.xml


 









































































































The table will describe the validator rules available with the validator-rules.xml file provided by the Struts Community.
RuleDescription

byte

Checks value contained by field can be converted to java byte type

byteLocale

Checks value contained by field can be converted to java byte type using the number formatting convention for the current locale.

creditCard

Checks for the valid card number supplied by major companies like VISA, MASTERCARD etc.

date

Checks value contained by field can be converted to java.util.Date.

double

Checks value contained by field can be converted to double primitive type.

doubleRange

Checks value contained by field can be fitted into the primitive double range or not.

email

Checks value contained by field can be properly formatted email address or not.

float

Checks value contained by field can be converted to float primitive type.

floatLocale

Checks value contained by field can be converted to java float type using the number formatting convention for the current locale.

floatRange

Checks value contained by field can be fitted into the primitive float range or not.

integer

Checks value contained by field can be converted to int primitive type.

integerLocale

Checks value contained by field can be converted to java int type using the number formatting convention for the current locale.

intRange

Checks value contained by field can be fitted into the primitive int range or not.

long

Checks value contained by field can be converted to long primitive type.

longLocale

Checks value contained by field can be converted to java long type using the number formatting convention for the current locale.

longRange

Checks value contained by field can be fitted into the primitive long range or not.

mask

Validate the value with the given Regular Expression.

maxLength

Validate the maximum length should not be exceeded of the value with the value given in the property.

minLength

Validate the minimum length should not be exceeded of the value with the value given in the property.

required

Checks whether the value contain by the field is other than the whitespace.

short

Checks value contained by field can be converted to java short type

shortLocale

Checks value contained by field can be converted to java short type using the number formatting convention for the current locale.

url

Checks the given value is properly formatted URL or not.

validwhen

Determine the field is validated or not based on the specified test condition.

Standard validator-rules.xml file


The following is given the standard validator-rules.xml file. In the next section you will learn how to create your own validator rules. Till the time we are using the same validator-rules.xml which is the standard file comes with standard struts framework.


<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-->

<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">


<!--
$Id: validator-rules.xml 481833 2006-12-03 17:32:52Z niallp $


This file contains the default Struts Validator pluggable validator definitions. It is contained in struts-core.jar, and should be referenced in the struts-config.xml under the plug-in element for the ValidatorPlugIn.


<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/org/apache/struts/validator/validator-rules.xml, /WEB-INF/validation.xml"/>
</plug-in>


These are the default error messages associated with each validator defined in this file. They should be added to your projects ApplicationResources.properties file or you can associate new ones by modifying the pluggable validators msg attributes in this file.


# Struts Validator Error Messages


errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.


errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.


errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.


Note: Starting in Struts 1.2.0 the default javascript definitions have been consolidated to commons-validator. The default can be overridden
by supplying a <javascript> element with a CDATA section, just as in struts 1.1.


-->


<form-validation>


    <global>


        <validator name="required"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateRequired"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        msg="errors.required"/>


 


        <validator name="requiredif"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateRequiredIf"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        msg="errors.required"/>


 


        <validator name="validwhen"
        msg="errors.required"
        classname="org.apache.struts.validator.validwhen.ValidWhen"
        method="validateValidWhen"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
/>


        <validator name="minlength"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateMinLength"
        methodParams="j
ava.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.minlength"
        jsFunction="org.apache.commons.validator.javascript.validateMinLength"
/>


        <validator name="maxlength"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateMaxLength"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.maxlength"
        jsFunction="org.apache.commons.validator.javascript.validateMaxLength"
/>


        <validator name="mask"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateMask"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.invalid"
/>


        <validator name="byte"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateByte"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.byte"
        jsFunctionName="ByteValidations"
/>


        <validator name="short"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateShort"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.short"
        jsFunctionName="ShortValidations"
/>


        <validator name="integer"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateInteger"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.integer"
        jsFunctionName="IntegerValidations"
/>


        <validator name="long"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateLong"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.long"
/>


        <validator name="float"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateFloat"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.float"
        jsFunctionName="FloatValidations"/>


 


        <validator name="double"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateDouble"
        methodParams=
"java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.double"
/>


        <validator name="byteLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateByteLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.byte"
/>


        <validator name="shortLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateShortLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.short"
/>


        <validator name="integerLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateIntegerLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.integer"
/>


        <validator name="longLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateLongLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.long"
/>


        <validator name="floatLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateFloatLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.float"/>


 


        <validator name="doubleLocale"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateDoubleLocale"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.double"
/>


        <validator name="date"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateDate"
        methodParams=
"java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.date"
        jsFunctionName="DateValidations"
/>


        <validator name="intRange"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateIntRange"
        methodParams=
"java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends="integer"
        msg="errors.range"/>


 


        <validator name="longRange"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateLongRange"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends="long"
        msg="errors.range"
/>


        <validator name="floatRange"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateFloatRange"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends="float"
        msg="errors.range"/>


 


        <validator name="doubleRange"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateDoubleRange"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends="double"
        msg="errors.range"
/>


        <validator name="creditCard"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateCreditCard"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.creditcard"
/>


        <validator name="email"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateEmail"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.email"/>


 


        <validator name="url"
        classname="org.apache.struts.validator.FieldChecks"
        method="validateUrl"
        methodParams="
java.lang.Object,
        org.apache.commons.validator.ValidatorAction,
        org.apache.commons.validator.Field,
        org.apache.struts.action.ActionMessages,
        org.apache.commons.validator.Validator,
        javax.servlet.http.HttpServletRequest
"
        depends=""
        msg="errors.url"/>


<!--
This simply allows struts to include the validateUtilities into a page, it should not be used as a validation rule.
-->

        <validator name="includeJavaScriptUtilities"
        classname=""
        method=""
        methodParams=""
        depends=""
        msg=""
       


  << Prev: Client Side Validation Next: Creating custom Valdator rules >>
Jsp Struts Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising