Explain about validator-rules.xml and validation.xml files ?

Validator framework is used to validate the form data and you no need to write any code in your form bean for validations and storing the error messages.Your Form Bean, extending one of the Validator’s Action Form subclasses, does the required validations.If you do not use Validator, you need to handle the data validations in the validate() method of Form Bean objects, and also handle storing of error messages if validationis fails.

Two configuration files used by Validator are validation.xml and validator-rules.xml. In order to enable and use the Validator, plug-in should be added in sturts-config.xml

<plug-in className=”org.apache.struts.validator.ValidatorPlugin”>
      <set-property property=”pathnames”

validator-rules.xml: This declares the validation routines and logical names are provided for the validations.It is also contains the client side javascript code for each validation routine. This validation routines are java methods plugged into the system to perform the specific validations.

<validator name=”required”

                    <![CDATA[// place the scripts here]]>

If the validation fails when it run, the message(i.e..in ApplicationResources.properties) corresponding to the key specified by the msg attribute will be returned.

validation.xml: This configuration files defines which validation routines must be applied for which form beans. Each form bean you want to validate has its own defination in this file. Inside that definations, you want to apply to the Form Beans’s fields. The definition in the file use the logical names of Form Beans from struts-config.xml file along with logical names of the validation routines from validation-rules.xml to tie together

             <form name=”logonForm”>
                    <field property=”username” depends=”required”>
                                <arg0 key=”prompt.username”/>
                   <field property=”username” depends=”required”>
                                <arg0 key=”prompt.password”/>

The depends attribute specifies the logical names of validation routines from the validator-rules.xml that should be applied to the field.


14 Responses

  1. […] Explain about validator-rules.xml and validation.xml files ? […]

  2. Hi

    iam little bit confusion about these two differences plz explain in detail

    and what sution we r use in real time and explain with programatic.

  3. can u say about xml validator modules

  4. i did’nt get explain in detail

  5. the validation fails when it run and what you said worked perfectly! youre brilliant. thank you.

  6. wow

  7. need examples using validator-rules.xml and validator.xml for generating alert messages during form submission

  8. want a pop message namely “Your data has been successfully saved” on submitting the form using struts

  9. If you ever want to see a reader’s feedback 🙂 , I rate this post for 4/5. Decent info, but I have to go to that damn msn to find the missed bits. Thanks, anyway!

  10. Hi, I implemented both validaion.xml and validator-rules.xml for one trial app which has two strings in bean named username and password. My doubt is when i click submit i have to get two alert boxes first for username and next for password but am getting only one alert box with two messages in the same. please help me.. 😦

  11. Hi
    I have a simple servlet application. I am trying to use commons validator to validate the form fields at server side. Please let me know the steps to configure this.

  12. hi thank you very much it’s so interesting

  13. how to differetiate twi properties files in programmatic approach and declarative approach?
    for example


    my.err.msg=username is mandatory


    my.err.pwd=password is mandatory

    in struts-config.xml

    how to differ in validation.xml and formbean class?

  14. Thank you so much..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: