xwork / docs / wikidocs / Validation Framework.html

<html>
    <head>
        <title>XWork : Validation Framework</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            XWork : Validation Framework
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Jul 22, 2004 by <font color="#0050B2">unkyaku</font>.
				    </div>

				    <ul class="star">
<li> Overview</li>
<li> <a href="Standard Validators.html" title="Standard Validators">Standard Validators</a> - details on validators bundled with XWork</li>
<li> <a href="Building a Validator.html" title="Building a Validator">Building a Validator</a></li>
<li> <a href="Generic Object Validation.html" title="Generic Object Validation">Generic Object Validation</a></li>
</ul><p class="paragraph"><h2 class="heading2"><a name="ValidationFramework-Overview"> Overview</a></h2></p>The validation framework in XWork is designed to help you apply simple validation rules to your Actions before they are executed. <p class="paragraph">At its core, the framework takes just about any object and a String context name for which to validate that object. This allows you to have different validation rules for the same class in different contexts. You can define default validation rules in the class-level validation file (<b class="strong">ClassName-validation.xml</b>), and then define validation rules which are added on top of these for a specific context (<b class="strong">ClassName-contextName-validation.xml</b>).  The validation rules are applied in the order they are listed in the validation files and error messages are saved into the Object (if it implements ValidationAware).</p>In the case of Action validation, which is what most XWork users will be doing, the class name is the Action class name and the context is the Action alias.<br/>

<p class="paragraph"><h2 class="heading2"><a name="ValidationFramework-RegisteringValidators"> Registering Validators</a></h2></p>Validation rules are handled by validators, which must be registered with the ValidatorFactory. This may either be done programmatically, using the registerValidator(String name, Class clazz) static method of the ValidatorFactory, or by adding a file named <b class="strong">validators.xml</b> to the root of the classpath that contains this information.  The syntax for <b class="strong">validators.xml</b> is:<br/>

<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;validators&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;required&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.RequiredFieldValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;requiredstring&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.RequiredStringValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;stringlength&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.StringLengthFieldValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;int&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.IntRangeFieldValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;date&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.DateRangeFieldValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;expression&quot;</span>&#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.ExpressionValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;fieldexpression&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.FieldExpressionValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;email&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.EmailValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;url&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.URLValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;visitor&quot;</span> &#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.VisitorFieldValidator&quot;</span>/&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator name=<span class="xml&#45;quote">&quot;conversion&quot;</span>&#10;        class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator&quot;</span>/&gt;</span>&#10;<span class="xml&#45;tag">&lt;/validators&gt;</span></pre>
</div></div><br/>

<p class="paragraph"><h2 class="heading2"><a name="ValidationFramework-TurningonValidation"> Turning on Validation</a></h2></p>The process of applying validation rules to an Action before it is executed is handled by the ValidationInterceptor.  As such, all that is required to enable validation for an Action is to declare the ValidationInterceptor in your XWork config file and add an interceptor-ref to it for your Action.  See <a href="Configuration.html" title="Configuration">XW:Configuration</a> for details on how to construct your XWork config file.  Here&#039;s a simple example:<br/>

<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;xwork&gt;</span>&#10;    <span class="xml&#45;tag">&lt;package name=<span class="xml&#45;quote">&quot;example&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;interceptors&gt;</span>&#10;            <span class="xml&#45;tag">&lt;interceptor name=<span class="xml&#45;quote">&quot;validator&quot;</span> &#10;                class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.validator.ValidationInterceptor&quot;</span>/&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/interceptors&gt;</span>&#10;&#10;        <span class="xml&#45;tag">&lt;action name=<span class="xml&#45;quote">&quot;Foo&quot;</span> class=<span class="xml&#45;quote">&quot;com.opensymphony.xwork.SimpleAction&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;foo&quot;</span>&gt;</span>17<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;bar&quot;</span>&gt;</span>23<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;success&quot;</span> type=<span class="xml&#45;quote">&quot;chain&quot;</span>&gt;</span>&#10;                <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;actionName&quot;</span>&gt;</span>Bar<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;/result&gt;</span>&#10;            <span class="xml&#45;tag">&lt;interceptor&#45;ref name=<span class="xml&#45;quote">&quot;validator&quot;</span>/&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/action&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/package&gt;</span>&#10;<span class="xml&#45;tag">&lt;xwork&gt;</span></pre>
</div></div><p class="paragraph">Bear in mind that the ValidationInterceptor only performs validation.  The Action will still be executed even if there are any validation errors.</p><h2 class="heading2"><a name="ValidationFramework-DefiningValidationRules"> Defining Validation Rules</a></h2><p class="paragraph">To define validation rules for an Action, create a file named <b class="strong">ActionName-validation.xml</b> in the same package as the Action. You may also create alias-specific validation rules which add to the default validation rules defined in <b class="strong">ActionName-validation.xml</b> by creating another file in the same directory named <b class="strong">ActionName-aliasName-validation.xml</b>.  In both cases,  <b class="strong">ActionName</b> is the name of the Action class, and <b class="strong">aliasName</b> is the name of the Action alias defined in the <b class="strong">xwork.xml</b> configuration for the Action.</p>The framework will also search up the inheritance tree of the Action to find validation rules for directly implemented interfaces and parent classes of the Action.  This is particularly powerful when combined with ModelDriven Actions and the <a href="Standard Validators.html#StandardValidators-VisitorFieldValidator" title="VisitorFieldValidator on Standard Validators">VisitorFieldValidator</a>.  Here&#039;s an example of how validation rules are discovered.  Given the following class structure:<br/>

<ul class="star">
<li> interface Animal;</li>
<li> interface Quadraped extends Animal;</li>
<li> class AnimalImpl implements Animal;</li>
<li> class QuadrapedImpl extends AnimalImpl implements Quadraped;</li>
<li> class Dog extends QuadrapedImpl;</li>
</ul><br/>
The framework method will look for the following config files if Dog is to be validated:<br/>

<ol>
<li> Animal</li>
<li> Animal-aliasname</li>
<li> AnimalImpl</li>
<li> AnimalImpl-aliasname</li>
<li> Quadraped</li>
<li> Quadraped-aliasname</li>
<li> QuadrapedImpl</li>
<li> QuadrapedImpl-aliasname</li>
<li> Dog</li>
<li> Dog-aliasname</li>
</ol><p class="paragraph">While this process is similar to what the <a href="Localization.html" title="Localization">XW:Localization</a> framework does when finding messages, there are some subtle differences.  The most important difference is that validation rules are discovered from the parent downwards.</p><h3 class="heading3"><a name="ValidationFramework-SyntaxforValidationRules">  Syntax for Validation Rules</a></h3><p class="paragraph">Here is a sample config file containing validation rules for SimpleAction from the Xwork test cases:</p><div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;&#33;DOCTYPE validators PUBLIC <span class="xml&#45;quote">&quot;&#45;//OpenSymphony Group//XWork Validator 1.0.2//EN&quot;</span> &#10;<span class="xml&#45;quote">&quot;&#104;ttp://www.opensymphony.com/xwork/xwork&#45;validator&#45;1.0.2.dtd&quot;</span>&gt;</span>&#10;<span class="xml&#45;tag">&lt;validators&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;bar&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;required&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>You must enter a value for bar.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;int&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;min&quot;</span>&gt;</span>6<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;max&quot;</span>&gt;</span>10<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>bar must be between $&#123;min&#125; and $&#123;max&#125;, current value is $&#123;bar&#125;.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;date&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;date&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;min&quot;</span>&gt;</span>12/22/2002<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;max&quot;</span>&gt;</span>12/25/2002<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>The date must be between 12&#45;22&#45;2002 and 12&#45;25&#45;2002.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;foo&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;int&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;min&quot;</span>&gt;</span>0<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;max&quot;</span>&gt;</span>100<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message key=<span class="xml&#45;quote">&quot;foo.range&quot;</span>&gt;</span>Could not find foo.range&#33;<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator type=<span class="xml&#45;quote">&quot;expression&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;expression&quot;</span>&gt;</span>foo &amp;gt; bar<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;        <span class="xml&#45;tag">&lt;message&gt;</span>Foo must be greater than Bar. Foo = $&#123;foo&#125;, Bar = $&#123;bar&#125;.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/validator&gt;</span>&#10;<span class="xml&#45;tag">&lt;/validators&gt;</span></pre>
</div></div><p class="paragraph">All &lt;validator&gt; (and &lt;field-validator&gt;) elements must have a <em class="emphasis">type</em> attribute, which refers to a name of a Validator registered with the ValidatorFactory as described above.  These elements may also have &lt;param&gt; elements with name and value attributes to set arbitrary parameters into the Validator instance.</p>All &lt;validator&gt; (and &lt;field-validator&gt;) elements must also define one <b class="strong">message</b> subelement, which defines the message that should be added to the Action if the validator fails.  By default, the message will be that contained in the body of the message tag.  The <b class="strong">message</b> element also has one optional attribute, <em class="emphasis">key</em>, which specifies a message key to look up in the Action&#039;s ResourceBundles using getText() from LocaleAware if the Action implements that interface (as ActionSupport does). This provides for Localized messages based on the Locale of the user making the request (or whatever Locale you&#039;ve set into the LocaleAware Action).  When a <em class="emphasis">key</em> is specified, any text contained in the body of the message tag becomes the default message if a message cannot be found for the given key.<p class="paragraph">If the validator fails, the validator is pushed onto the ValueStack and the message &#8211; either the default or the locale-specific one if the <em class="emphasis">key</em> attribute is defined (and such a message exists) &#8211; is parsed for $&#123;...&#125; sections which are replaced with the evaluated value of the string between the $&#123; and &#125;. This allows you to parameterize your messages with values from the validator, the Action, or both. Here is an example of a parameterized message:</p><div class="code"><div class="codeContent">
<pre>bar must be between $&#123;min&#125; and $&#123;max&#125;, current value is $&#123;bar&#125;.</pre>
</div></div><p class="paragraph">This will pull the min and max parameters from the IntRangeFieldValidator and the value of bar from the Action.</p>A more complete example of the validation rules can be found <a href="Sample Validation Rules.html" title="Sample Validation Rules">here</a>.<br/>

<div class="panel"><div class="panelContent" style="background-color: #ffffce; ">
<p class="paragraph"><img class="rendericon" src="./icons/emoticons/information.png" height="16" width="16" align="absmiddle" alt="" border="0"/> Since validation rules are in an XML file, you must make sure you escape special characters.  For example, notice that in the expression validator rule above we use &quot;&amp;gt;&quot; instead of &quot;&gt;&quot;.  Consult a resource on XML for the full list of characters that must be escaped.  The most commonly used characters that must be escaped are:  &amp; (use &amp;amp;&#41;,  &gt; (user &amp;gt;&#41;, and &lt; (use &amp;lt;&#41;.</p>
</div></div>
<p class="paragraph"><h4 class="heading4"><a name="ValidationFramework-Validatorvs.FieldValidator"> Validator vs. Field-Validator</a></h4></p>The &lt;field-validator&gt; elements are basically the same as the &lt;validator&gt; elements except that they inherit the <em class="emphasis">fieldName</em> attribute from its enclosing &lt;field&gt; element.  FieldValidators will have their <em class="emphasis">fieldName</em> automatically filled with the value of the parent &lt;field&gt; element&#039;s <em class="emphasis">fieldName</em> attribute.  The reason for this structure is to clearly group the validators for a particular field under one element, and because the <em class="emphasis">fieldName</em> attribute would otherwise always have to be set for all field validators. <p class="paragraph">That said, it&#039;s perfectly legal to only use validator elements without the field elements and set the <em class="emphasis">fieldName</em> attribute for each of them.  The following are effectively equal:</p><div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;bar&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;required&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;message&gt;</span>You must enter a value for bar.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;<span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;<span class="xml&#45;tag">&lt;validator type=<span class="xml&#45;quote">&quot;required&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;fieldName&quot;</span>&gt;</span>bar<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;    <span class="xml&#45;tag">&lt;message&gt;</span>You must enter a value for bar.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;<span class="xml&#45;tag">&lt;/validator&gt;</span></pre>
</div></div>
<p class="paragraph"><h3 class="heading3"><a name="ValidationFramework-ShortcircuitingValidators"> Short-circuiting Validators</a></h3></p>Beginning with XWork 1.0.1 (bundled with WebWork 2.1), it is possible to short-circuit a stack of validators.  Here is another sample config file containing validation rules from the Xwork test cases:<br/>

<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;&#33;DOCTYPE validators PUBLIC <span class="xml&#45;quote">&quot;&#45;//OpenSymphony Group//XWork Validator 1.0.2//EN&quot;</span> &#10;<span class="xml&#45;quote">&quot;&#104;ttp://www.opensymphony.com/xwork/xwork&#45;validator&#45;1.0.2.dtd&quot;</span>&gt;</span>&#10;<span class="xml&#45;tag">&lt;validators&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;email&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;required&quot;</span> short&#45;circuit=<span class="xml&#45;quote">&quot;true&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>You must enter a value for email.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;email&quot;</span> short&#45;circuit=<span class="xml&#45;quote">&quot;true&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>Not a valid e&#45;mail.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;email2&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;required&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>You must enter a value for email2.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;        <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;email&quot;</span>&gt;</span>&#10;            <span class="xml&#45;tag">&lt;message&gt;</span>Not a valid e&#45;mail2.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;        <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator type=<span class="xml&#45;quote">&quot;expression&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;expression&quot;</span>&gt;</span>email.equals(email2)<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;        <span class="xml&#45;tag">&lt;message&gt;</span>Email not the same as email2<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/validator&gt;</span>&#10;    <span class="xml&#45;tag">&lt;validator type=<span class="xml&#45;quote">&quot;expression&quot;</span> short&#45;circuit=<span class="xml&#45;quote">&quot;true&quot;</span>&gt;</span>&#10;        <span class="xml&#45;tag">&lt;param name=<span class="xml&#45;quote">&quot;expression&quot;</span>&gt;</span>email.startsWith(&#039;mark&#039;)<span class="xml&#45;tag">&lt;/param&gt;</span>&#10;        <span class="xml&#45;tag">&lt;message&gt;</span>Email does not start with mark<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/validator&gt;</span>&#10;<span class="xml&#45;tag">&lt;/validators&gt;</span></pre>
</div></div><p class="paragraph">Notice that some of the &lt;field-validator&gt; and &lt;validator&gt; elements have the <em class="emphasis">short-circuit</em> attribute set to true.  Since validators are evaluated in the order they are declared, a validator with this attribute set to true will prevent the evaluation of subsequent validators if the validator fails, where failure is determined by the addition of an error (action or field error depending on the type of validator) to the ValidationContext of the object being validated.</p>A field-validator that gets short-circuited will only prevent other field-validators for the same field from being evaluated.  A non field-validator that gets short-circuited will completely break out of the validation stack &#8211; no other validators will be evaluated.<p class="paragraph">As mentioned above,  the framework will also search up the inheritance tree of the action to find default validations for interfaces and parent classes of the Action.  If you are using the <em class="emphasis">short-circuit</em> attribute and relying on default validators higher up in the inheritance tree, make sure you don&#039;t accidentally short-circuit things higher in the tree that you really want!</p><img class="rendericon" src="./icons/emoticons/warning.png" height="16" width="16" align="absmiddle" alt="" border="0"/>&#160;<b class="strong">Upgrade Alert</b>:  The <em class="emphasis">short-circuit</em> attribute was added to the DTD in version 1.0.2.  Your validation files must use version 1.0.2 of the xwork-validation.dtd to validate properly.


				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Nov 14, 2004 17:31</font></td>
		    </tr>
	    </table>
    </body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.