Grails bean-fields plugin

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-05-23T21:21:37Z Indexed on 2010/05/23 21:31 UTC
Read the original article Hit count: 456

Filed under:
|
|
|

Hi,

I'm having problems using the Grails bean-fields plugin with a class this is annotated Validateable, but is not a domain/command class. The root cause of the problem appears to be in this method of BeanTagLib.groovy

private def getBeanConstraints(bean) {
    if (bean?.metaClass?.hasProperty(bean, 'constraints')) {
        def cons = bean.constraints
        if (cons != null) {
            if (log.debugEnabled) {
                log.debug "Bean is of type ${bean.class} - the constraints property was a [${cons.class}]"
            }

            // Safety check for the case where bean is no a proper domain/command object
            // This avoids confusing errors where constraints comes back as a Closure
            if (!(cons instanceof Map)) {
                if (log.warnEnabled) {
                    log.warn "Bean of type ${bean.class} is not a domain class, command object or other validateable object - the constraints property was a [${cons.class}]"
                }
            }
        } else {
            if (log.warnEnabled) {
                log.warn "Bean of type ${bean.class} has no constraints"
            }
        }
        return cons
    } else return null
}

I tested out this method above in the grails console and when I pass an instance of MyBean into this method, it logs:

Bean of type ${bean.class} is not a domain class, command object or other validateable object - the constraints property was a [${cons.class}]

Because the constraints are returned as an instance of Closure instead of a Map. If I could figue out how to get a Map reference to the constraints of a @Validateable class (that is not a domain/command class), I guess I could resolve the problem.

Thanks, Don

© Stack Overflow or respective owner

Related posts about grails

Related posts about groovy