I wrote a validator that uses scripting snippets to determine validity. The validator uses Jakarta BSF so supports any scripting language supported by BSF like BeanShell, JavaScript, Jython, Groovy (I believe), etc.

I was starting to refactor out my app's validation code to be usable by commons-validator, when I realized most of the resulting validations ended up being one line. For example, to make sure a particular employee existed, the validation was simply "empFacade.getEmployee(key) != null". Rather than writing a ton of one line validator or shoving them all into one umbrella validator, I decided to write this validator.

Here is an example of its use:

<field property="value" depends="bsf">
 <var>
   <var-name>eval</var-name>
   <var-value>value.equals("foo")</var-value>
 </var>
</field>

The validator works and the unit tests pass, but I'm still working on a clean way to pass it business objects. Right now, if you want to put variables in the scope, you need to create your own BSFManager and BSFEngine beforehand and add them as Validator parameters. For simple cases with just BeanShell, neither are required, just the usual target object and Field.

Again, I can submit the code, unit tests, and patches if needed. I certainly do appreciate how flexible validator is to be able to support many types of implementations.

Don

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to