Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 9-8.Example of Complex Boolean Logic in Valang


{ postalCode :
(? is blank or country is blank)
or ((country in 'United States', 'France' and length(?) = 5)
or (country = 'Belgium' and length(?) = 4)
or country not in
'United States', 'France', 'Belgium') :
'' : 'postalCodeInvalid' : ?, country, length(?) }


This constraint will fail if the country and postal code are not blank; if the country is
either the United States or France; if the length of the postal code is not 5 or the country is
Belgium; and if the length of the postal code is not 4. Other combinations of postal code and
country will be accepted as is by this constraint.
Also notice that the postal code, the country, and the length of the postal code are passed
as error arguments.
Valang supports a wide range of operators to allow for extensive testing of target objects.


Table 9-1.Operators Supported by Valang


Operator Types Null Safe Description


=, == Any No Tests equality of left and right
values.


!=, <>, >< Any No Tests inequality of left and right
values.


< N, D No Tests value to the left is less than
value to the right. Only supports
numbers and dates.


<=, =< N, D No Tests value to the left is less than or
equal to value to the right. Only
supports numbers and dates.



N, D No Tests value to the left is more than
value to the right. Only supports
numbers and dates.



=>, >= N, D No Tests value to the left is more than
or equal to value to the right. Only
supports numbers and dates.


IN (, )* Any No Tests equality of value to the left
with one of the values to the right.


NOT IN (, )* Any No Tests inequality of value to the left
with all of the values to the right.


BETWEEN AND N, D No Tests value to the left is more than
or equal to first value to the right
and less than or equal to second
value to the right. Only supports
numbers and dates.


NOT BETWEEN AND N, D No Tests value to left is less than first
value to the right or more than
second value to the right. Only
supports numbers and dates.
Continued


CHAPTER 9 ■VALIDATION 269
Free download pdf