Note that there are some explanatory texts on larger screens.

plurals
  1. PODependency Injection In Grails Domain Controllers
    primarykey
    data
    text
    <p>I'm trying to create a a custom constraint. I've put the logic in a service:</p> <pre><code>class RegExpManagerService { boolean transactional = false def messageSource def lookupRegexp(regExpression,Locale locale) { def pattern = messageSource.getMessage( regExpression,null,locale ) return pattern } def testRegexp(regExpression,text,Locale locale) { return text ==~ lookupRegexp(regExpression,locale) } } </code></pre> <p>and tried to inject it in my domain controller:</p> <pre><code>class Tag extends IbidemBaseDomain { def regExpManagerService static hasMany=[itemTags:ItemTag] static mapping = { itemTags fetch:"join" } //Long id Date dateCreated Date lastUpdated String tag // Relation Tagtype tagtype // Relation Customer customer // Relation Person updatedByPerson // Relation Person createdByPerson static constraints = { dateCreated(nullable: true) lastUpdated(nullable: true) tag(blank: false,validator: {val,obj -&gt; regExpManagerService.testRegexp(obj.tagtype.regexpression,val,local) }) tagtype(nullable: true) customer(nullable: true) updatedByPerson(nullable: true) createdByPerson(nullable: true) } String toString() { return "${tag}" } } </code></pre> <p>When the constraint gets executed I get this error:</p> <pre><code>2009-08-24 18:50:53,562 [http-8080-1] ERROR errors.GrailsExceptionResolver - groovy.lang.MissingPropertyException: No such property: regExpManagerService for class: org.maflt.ibidem.Tag org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingPropertyException: No such property: regExpManagerService for class: org.maflt.ibidem.Tag </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload