title: Reusing Custom Expression Validator in Struts 2
body: <p>In Struts 2 we can develop <code>@CustomValidator</code> which can be used in application wide</p>
  <pre><code>@CustomValidator(type = &quot;CustomerNumberValidator&quot;, fieldName = &quot;customerNo&quot;)
  </code></pre>
  <p>For validation <em>more</em> than one field we use <code>@ExpressionValidator</code></p>
  <pre><code>@ExpressionValidator(expression = 
  &quot;( (!''.equals(account.firstName) &amp;&amp; (!''.equals(account.lastName) )
     || (presonalAccount == false)&quot;, 
     key = &quot;validate.account.name&quot;)
  </code></pre>
  <p>If the expression is too complicated and needs to work on <em>more</em> than one field we use OGNL to call the static method. The static method will do the validation and return a <code>boolean</code> for example</p>
  <pre><code>@ExpressionValidator(expression = &quot;@foo.bar.CalendarUtil@compareDates(fromDate,toDate)&quot;, key = &quot;validate.date.before&quot;)
  </code></pre>
  <p>Above is some how a <em>Custom</em> Expression Validator !</p>
  <p>And we use <code>@foo.bar.CalendarUtil@compareDates</code> in application wide to make this validation for us.</p>
  <p>Is there another approach which enables us to use a custom wide validator?!</p>
  <p>Is there any custom expression validator which can be added to Struts and we can call it in <code>Action</code> in the way we use <code>@CustomValidator</code>?</p>