Conditional validation in domain objects

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Conditional validation in domain objects

yenoom
If I have a domain object with a constraint such as the following...

@Property constraints = {
          userId(blank:false,length:5..15,unique:true)
}

If I do not enter a userId in the form I get error messages that the userid has not been entered AND the userId "...does not fall within the valid length range from [5] to [15]". Is there a way to make validations conditional on other validations for the same field ? For example, to say only check the length of a field if it is not blank ? I'm coming from a Struts background where this is possible.