Simple validwhen example
The Last Name must be entered IF a First Name is present.
Both Fields Example
Either both the fields must be present OR both must be absent.
Numeric Compare Example
Maximum value must be numeric and greater than the minimum.
Address Validation example
If any one of the address fields is present then Address Line 1, City and State must be present. Address Line 2 is optional.
Tips on Using the validwhen Validator
- Check Out the User Guide.
- Greater Than and Less Than (i.e. > and <) can't be used directly in the validation.xml - you need to use > and < instead.
- All comparisons must be enclosed in parens
- Only two items may be joined with and or or - so that means if you want to test three separate things, you need to use parenthesis (brackets) appropriately - see the address validation above.
Issues When (trying) to Use the validwhen Validator
- java.lang.NoClassDefFoundError antlr.TokenStream - validwhen requires antlr.jar - its distributed in the Struts binary distribution in the lib folder along with all the other jars.
- JavaScript Validation Not Working - There is no JavaScript validator for validwhen - its server side only
- unexpected token: OR Error - tokens and and or should be lower case
- Other unexpected token Errors - somethings wrong with the test's value - the expression can't be parsed. You need to check it carefully to make sure its correctly specified.
- Its Not Working! - check the logs / console for any exceptions.