groovy.lang Interface MetaClass – A MetaClass within Groovy defines the behaviour of any given Groovy or Java class. The MetaClass interface defines two parts. The client API, which is defined via the extend MetaObjectProtocol interface and the contract with the Groovy runtime system. In general the compiler and Groovy runtime engine interact with methods on this class whilst MetaClass clients interact with the method defined by the MetaObjectProtocol interface.
This is the example how to use Groovy’s MetaClass:
[groovy]
class Individual {
String nationality
String title
String givenName
String middleName;=
String surname
String dob
String occupation
Individual() {}
Individual(def map) {
metaClass.setProperties(this, map.findAll { key, value -> this.hasProperty(key) })
}
}
[/groovy]
There is no getter and setter for a POJO object like class Individual. When you initialise it:
[groovy]
individual = new Individual(params.("applicant" + i))
[/groovy]
will match and set all the data in your submit form, with field name like:
applicant1.nationality
applicant1.title
…
applicant1.occupation