Grails overloaded controller workaround I had an overloaded method, but Grails doesn't allow overloaded methods in controller actions.  The overloaded method looked like this:

def punch(User user, User source) {
    user.userVersion++
    punch(user, source, null, null)
  }


 def punch(User user, User source, String latitude, String longitude) {

     UserPunch userPunch = new UserPunch()
     userPunch.punchClockStatus = user.punchClockStatus
     userPunch.user = user
     userPunch.job = user.job
     userPunch.task = user.task
     userPunch.date = new Date()
     userPunch.source = source
     userPunch.save(flush: true)
     if (latitude != null) {
        userPunch.latitude = latitude
        userPunch.longitude = longitude
     }
     if (userPunch.hasErrors())
        userPunch.errors.each {
            log.error it
     }
}


In order to get around the restrictions on overloaded methods, I used a try/catch, like this:

def punch(User user, User source, String latitude, String longitude) {

    UserPunch userPunch = new UserPunch()
    userPunch.punchClockStatus = user.punchClockStatus
    userPunch.user = user
    userPunch.job = user.job
    userPunch.task = user.task
    userPunch.date = new Date()
    userPunch.source = source
    userPunch.save(flush: true)
    try {
        userPunch.latitude = latitude
        userPunch.longitude = longitude
    } catch (MissingPropertyException e) {
        user.userVersion++
    }
    if (userPunch.hasErrors())
        userPunch.errors.each {
            log.error it
        }
}


Does this look like it will work right? Does anyone have a better solution?
If you use default parameters, you won't need to overload the function.

def punch(User user, User source, String latitude=null, String longitude=null)