0
votes

Let's say I have a command-object containing seven fields(String monday, String tuesday, ..) and I need to validate it just to check if at least one of them exists.

Because of working with Grails 1.3.7 I tried to use instance validation with extended-validation-plugin(not rich-domain) but I couldn't make it work. Basically, it does not recognise non-field validator inside of static constraints block.

static constraints = { availabilitySelected(validator: { ... }) ...

and I get:

Exception Message: No such property: availabilitySelected

Is there any other smart way to do it? I just do not want to add validator for every single field in my command object.

Thanks

1

1 Answers

0
votes

You can access the object being validated via the two / three parameter form of a custom validator.

myField(validator: { val, obj, errors -> if( obj.blah.empty && obj.blah.empty ) { errors.reject( ... ) } )

http://grails.org/doc/1.3.7/ref/Constraints/validator.html