How To Apply Multiple XML Validations On Same Field In Struts 2
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-validator type="requiredstring" short-circuit="true">
<message>Entered value must be string..!!!!</message>
<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 Author ♦