Tuesday, November 6, 2012

Domain event features

The Grails Domain class has some really nice event features in the afterUpdate, beforeUpdate.
What I wanted was if the domain.status was set to completed then domain.completedDate would be filled in with the current date. And if the domain.status was set to anything else, then domain.completedDate would be made null.
Was pretty easy to add this code to the domain


    def afterUpdate() {
        if (status == Status.COMPLETED) {
        if (completedDate)
        completedDate = new Date()
        } else {
        completedDate = null
        }
   }




No comments:

Post a Comment