i 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.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
|
<field name="email">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message>Entered value must be string..!!!!</message>
</field-validator>
<field-validator type="email">
<message>Enter valid email id..!!</message>
</field-validator>
</field>
|
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….!!!!!!
No comments:
Post a Comment