« Return to Thread: beforeInsert event problem

beforeInsert event problem

by Marc Palmer Local :: Rate this Message:

Reply to Author | View in Thread

Hi All,

I tried to use beforeInsert on a domain class for the first time  
today, following an example like the one in the docs:

class Person {
    Date dateCreated
    def beforeInsert = {
        dateCreated = new Date()
    }
}

... my assignment is different of course but the same principle. All  
fine except... this is called after validate() so this is not useful  
at all if you have any "required" constraints on the properties.

You could work around it by assigning some non-null value at init time  
to the property so it survives validation.

However this implies that validation is either being performed twice -  
before the calls to events and again after, or only once before  
calling events, in which case events can bypass constraints and hence  
introduce bugs.

Anybody got any views on this?

I would have thought that the events have to occur before validation,  
always.

Marc


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: beforeInsert event problem