views:

288

answers:

2

I have following two domain classes in Grails 1.1.2:

class A implements Serializable {
 MyEnumType myField
 Date fieldChanged

 void setMyField(MyEnumType val) {
  if (myField != null && myField != val) {
   myField = val
   fieldChanged = new Date()
  }
 }
}

class B extends A {
 List children
 void setMyField(MyEnumType val) {
  if (myField != null && myField != val) {
   myField = val
   fieldChanged = new Date()
   children.each { child -> child.myField = val }
 }
}

When I set B instance's myField, I get the setter into the cycle... myField = val line calls setter again instead of assiging the new value.

Any hint how to override the setter correctly? Thanks

A: 

Have you tried this ?

Philippe
Don't see your point exactly... Could you write more?
Pavel P
A: 

Use the this keyword to avoid calling the getter or setter:

this.myField = val

See http://groovy.codehaus.org/Groovy+Beans#GroovyBeans-Propertyandfieldrules

Justin Ludwig