0

I'm new to Grails/Groovy, and so please bear with me as I try to understand a piece of code that I had come across in a book.

It is a simple Album domain class:

class Album { String artist String title List songs = [] List durations = [] static constraints = { artist blank: false title blank: false songs minSize:1, validator:{ val, obj -> if(val.size() != obj.durations.size()) return "songs.durations.not.equal.size" } } 

My question comes from the constraints property block of code.
In the validator constraint, the author uses a closure.
But what exactly are "val" and "obj"? What values will they be given?

Also, a bonus question, what type is "constraints"? I don't think it is a map as they are defined as [ ] in Groovy. Coming from a Java perspective, x = { .. } is an array, but I'm not sure it is the same in Groovy.

Thanks for the help!

0

1 Answer 1

1

Your first question, val and obj parameters refer to the value of the property and a pointer to the instance, respectively. The documentation for custom validation routines explains this in further detail.

As for the bonus question constraints is a Groovy closure.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.