concept custom validator in category java

appears as: custom validator, custom validators
Struts 2 in Action

This is an excerpt from Manning's book Struts 2 in Action.

Eventually, you’ll have some validation logic that isn’t handled by the built-in validators. At that point, you’ll have two choices. If your validation logic is something that you can foresee reusing in the future, it probably makes sense to implement a custom validator. However, if your validation logic truly appears to be a quirky requirement that will most likely only be applied in this one case, it makes more sense to put it in the validate() method. In a one-off case like this, it’s much more efficient to take the quick and local fix.

10.3. Writing a custom validator

Writing your own custom validator is little different than writing any of the other custom Struts 2 components. We’ve already seen how to write custom interceptors, results, and type converters. In this section, we follow a familiar path of extending a convenience class, declaring our new component with XML, then wiring it in to a working code example. For our example, we write a custom validator that checks for a certain level of password integrity. After we implement it, we add it to the Struts 2 Portfolio Register action to make sure that people are using strong passwords for their accounts.