How To Apply Multiple XML Validations On Same Field In Struts 2

Struts » on Oct 25, 2011 { 1 Comment } By Sivateja

Hi there, this is very important concept in real time, applying multiple validation rules on same field.  For example we have Email filed and we would like to apply 2 validations to this field like email, requiredstring. [ hey these 2 are rules right,  just go back and check the previous concept if not clear 🙂 ]

So we want users to enter email id which contains only string value.

Actually by default if one rule, suppose requiredstring failed no need to check email rule right, but by default struts 2 will verify email rule also.  So to avoid this, we need to write short-circuit=”true”.  What am saying if we apply 5 rules to one filed then if 1 rule is failed there is no need to check others right… 🙂 that what am saying hope it make sense.


<field name="email">

   <field-validator type="requiredstring" short-circuit="true">
        <param name="trim">true</param>
        <message>Entered value must be string..!!!!</message>

   <field-validator type="email">
    <message>Enter valid email id..!!</message>


Note: If first rule [ requiredstring ] failed, then struts 2 will not verify email rule as we given short-cricuit=”true”.  Same concept even if you apply 1000 rules hah  🙂 and that’s it nothing is more than this.

You can check practically in the next example….!!!!!!

​ ​​

You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


One Response to “How To Apply Multiple XML Validations On Same Field In Struts 2”
  1. Jagannath says:

    Hi, there are 2 file browse buttons and 3 submit on jsp page like “View Photo”,”view Signature” and “Submit”. I want to apply validation on submit button only,photo and signature must be used to display images after uploading. Other problem is if I click on a any button file path is removed how can I fix it?

    Thanks and Regards,
    Jagannath Kale


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.