An implementation of
Validator
that takes a Valang syntax string to define the set of validation rules it will apply. This instance is thread-safe.
The syntax of a Valang instruction is:
{ <key> : <expression> : <error_message> [ : <error_key> [ : <error_args> ] ] }
These instructions can be repeated and will be combined in a Validator instance. Each instruction will execute the expression on a target bean. If the expression fails the key will be rejected with the error message, error key and error arguments. If no error key is provided the key will be used as error key.
Some examples of the Valang syntax:
<bean id="myValidator" class="org.springmodules.validation.valang.ValangValidatorFactoryBean"> <property name="valang"><value><![CDATA[ { age : ? is not null : 'Age is a required field.' : 'age_required' } { age : ? is null or ? >= minAge : 'Customers must be {0} years or older.' : 'not_old_enough' : minAge } { valueDate : ? is not null : 'Value date is a required field.' : 'valueDate_required' } { valueDate : ? is null or (? >= [T<d] and [T>d] > ?) : 'Value date must be today.' : 'valueDate_today' } { firstName : ? has text : 'First name is a required field.' : 'firstName_required' } { firstName : ? has no text or length(firstName) <= 50 : 'First name must be no longer than {0} characters.' : 'firstName_length' : 50 } { size : ? has length : 'Size is a required field.' } { size : ? has no length or upper(?) in 'S', 'M', 'L', 'XL' : 'Size must be either {0}, {1}, {2} or {3}.' : 'size_error' : 'S', 'M', 'L', 'XL' } { lastName : ? has text and !(false) = true : 'Last name is required and not false must be true.' } ]]></value></property> </bean>
Custom property editors can be registered using org.springmodules.validation.valang.CustomPropertyEditor.
A custom visitor can be registered to use custom functions in the Valang syntax.
@author Steven Devijver
@see org.springmodules.validation.util.date.DefaultDateParser
@see org.springframework.validation.Validator
@since 23-04-2005