Skip to content
zhaber edited this page Jul 28, 2012 · 4 revisions

A preprocessing rule defines a sequence of converters and validators that must be applied to an input value before it can be processed by a controller.

The syntax for rule application declaration is:

parameterName rule

where parameterName is a valid Groovy variable name that starts from a lowercase letter.

For example, this grules script normalizes categoryId and login parameters:

categoryId trim //categoryid is a parameter name, trim - a converter 
login isAlnum

If a function (validator or converter) takes only one argument, its single parameter is implicitly equal to the value of a parameter processed by a current rule or a value passed from the previous converter if such exists, so categoryId trim actually means: call the function trim with a categoryId entry content and supersede the original value with a trimmed one. Analogously to the first rule, the isAlnum validator is called with the string value of the login parameter. The only difference is that if the function returns false, a validation error occurs.

To use a function with more than one parameter, just omit the first argument in the function call. For example:

id add(10) // add value 10 to id
Clone this wiki locally