tiistai 22. kesäkuuta 2010

Check if JSON object is undefined

on the callback of jQuery.getJSON(), you want to check if json.myObject is undefined. It's done in a groovy way:
function(json){
if (json.myObject){
// do stuff with myObject
} else {
// do not do stuff with myObject
}
}

Accessing Taglib from Service

From the service:


class MyService {
def grailsApplication

def method() {
def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
}
}

...now g can be used just as in GSP files.

Mystical message codes for numerical validation constraints

minSize -> class.prop.minSize.notmet
maxSize -> class.prop.maxSize.exceeded
size -> class.prop.size.toosmall & class.prop.size.toobig

min -> class.prop.min.notmet
max -> class.prop.max.exceeded
range -> class.prop.range.invalid (only if validated value is null), class.prop.size.toosmall , class.prop.size.toobig