编码
${personRequest.constraints.requestStatus.inList}
在我的gsp文件中抛出
NullPointerException,但是
new PersonRequest().constraints..可以工作。为什么?
constraints不是静态的吗?
请您参考如下方法:
从here复制(grails用户邮件列表)
but why accesing to static fields doesnt work?
Because the "constraints" static field is a closure property. It has no sub-properties relating to the constraints.
Grails evaluates this closure using a constraint builder which monitors "calls" to methods that don't exist, i.e. the property names you use:
type( inList: [xxxxx])...causes a method call to "type" with a Map parameter containing "inList" ==> some value.
From this info, Grails builds up a list of all the constraints
available and binds them to future instances of the domain class.So, when you access User.constraints statically, you are getting a
Closure.We -could- look at replacing the value of the static constraints property at runtime after evaluating the Closure it is initialized with. However this could be a bit "too much" magic. What do people think?
FYI it's like this now because until 0.4 (if I recall) constraints weren't static, and in 0.4 they can still be non-static. Only in 0.5
will we throw an exception/ignore non-static constraints.




