使用具有inlist约束和动态查找器的动态脚手架

时间:2012-11-09 18:40:44

标签: grails dns constraints scaffolding

Grails 2.0.4 - 使用带有inlist约束和动态查找器的动态脚手架。

我正在尝试在域对象的inList约束中使用动态查找器。 如果我在应用程序处于活动状态时通过run-app更改约束来采样2 = Aidy.findAll()*。代码,它可以很好地从引导的样本数据创建对象表单上的下拉列表。 但是,后续使用grails run-app引导应用程序失败并显示MissingMethodException。

//1- aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
//2- aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())

在域的inlist约束中使用findAll是个坏主意吗?有什么建议/建议吗?

缩写错误是

$ grails run-app
| Running Grails application
| Error 2012-11-09 12:54:16,589 [pool-5-thread-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   680 | run . .  in java.lang.Thread

Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
....
....
...

我有一个简单的示例项目:https://github.com/mlmclaug/scaffold_inlist.git 但它只是以下2个域对象,一个控制器和一个bootstrap.groovy

package edu.uvm
class Aidy {
    String code
    String desc
    Date startDate
    Date endDate
    String statusInd

    static constraints = {
        code(unique:true,blank:false, maxSize:4)
        desc(blank:false, maxSize:30)
        startDate(blank:false)
        endDate(blank:false)
        statusInd(blank:false, inList:["A","I"])
    }

}

package edu.uvm
class TreqMap {
        String aidyear
        String treq
        Integer seqno

        static constraints = {
            aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
            //aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())
            treq(blank:false, maxSize:6, inList:["BNOTE","SCERT","PERKIN","PNOTE","LNOTE","SNOTE"])
            seqno(blank:true, range:0..99)
       }
}

package edu.uvm
class TreqMapController {
    def scaffold = edu.uvm.TreqMap
}

import edu.uvm.Aidy
class BootStrap {

    def init = { servletContext ->
        new Aidy(code:'0910', desc:'July 2009 - June 2010', startDate:'07/01/2009', endDate:'06/30/2010', statusInd:'A').save(failOnError:true)
        new Aidy(code:'1011', desc:'July 2010 - June 2011', startDate:'07/01/2010', endDate:'06/30/2011', statusInd:'A').save(failOnError:true)
        new Aidy(code:'1112', desc:'July 2011 - June 2012', startDate:'07/01/2011', endDate:'06/30/2012', statusInd:'A').save(flush:true,failOnError:true)
        println "Loaded " + Aidy.count() + " Aid Years"
    }
    def destroy = {
    }
}

0 个答案:

没有答案
相关问题