gorm - Grails: how to set a meta-constraint on domain class property? -


i have contact class belongs subscription , want set hypothetic readonly constraint on subscription property, consumed in scaffold templates.

the class looks like

class contact {     static belongsto = [subscription: subscription]     static constraints = {      subscription(nullable: false, readonly: true) // hypothetic *readonly* constraint      name(blank: false)      email(blank: false, email: true)    }     integer id    string name    string email    string description } 

i found constrainedproperty.addmetaconstraint method "adds meta constraints non-validating informational constraint".

how call within domain class?

and how meta-constraint?

in scaffolding templates there property domainclass type org.codehaus.groovy.grails.commons.defaultgrailsdomainclass. these object has property constrainedproperties. have excess 'readonly' have this:

your domain class:

class contact {    static belongsto = [subscription: subscription]     static constraints = {        subscription(nullable: false, attributes: [readonly: true])      }     string description } 

in scaffolding template:

def ro = domainclass.constrainedproperties.subscription.attributes.readonly 

the defaultgrailsdomainclass has constructor attribute type class maybe can this:

def domainclass = new defaultgrailsdomainclass(contact.class) def ro = domainclass.constrainedproperties.subscription.attributes.readonly 

maybe there factory this, don't know.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -