这个错误的奇怪部分是页面有时会生成错误,有时不会。我不知道是什么原因造成的或为什么:
errors.GrailsExceptionResolver ClassCastException occurred when processing request: [GET] /birthFamily/aboutYouLifestyle
java.util.LinkedHashMap cannot be cast to groovy.lang.Closure. Stacktrace follows:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to groovy.lang.Closure
at com.nrfa.LifestyleCommand$__clinit__closure1.doCall(Wizard.groovy:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
有问题的命令对象:
@Validateable
public class LifestyleCommand {
Integer applicantNumber;
Smoke smoke
Drink drink
Occupation occupation
Set <String> hobby
String occupationDetails
static constraints = {
importFrom Applicant, include:["smoke", "drink", "occupation", "occupationDetails", "applicantNumber"]
}
}
堆栈跟踪中的第 302 行是命令对象约束中的“importFromApplicant”行。'java.util.LinkedHashMap cannot be cast to groovy.lang.Closure' 表示什么?
当我将约束替换为在申请人域中找到的约束的副本时,它也可以正常工作:
static constraints = {
applicantNumber (blank:false, nullable:false, range:1..2)
smoke (blank:true, nullable:true)
drink (blank:true, nullable:true)
occupation (blank:true, nullable:true)
occupationDetails (blank:true, nullable:true, maxSize:150)
}
编辑:
这是申请人的相关部分,它是一个域对象:
class Applicant {
static hasMany = [hobby:Hobby, ethnicity:Ethnicity]
Integer applicantNumber
String gender
Integer yearBorn
EyeColor eyeColor
HairColor hairColor
Integer heightFeet
Integer heightInches
static constraints = {
applicantNumber (blank:false, nullable:false, range:1..2)
gender (blank:true, nullable:true, validator: { value ->
if (value != null && value != '' && (value != "M" && value != "F")) {
return 'applicant.invalid.gender'
}
})
yearBorn (blank:true, nullable:true, validator: { value ->
if (value != null && (value < 1920 || value > 2014)) {
return 'applicant.invalid.yearBorn'
}
})
eyeColor (blank:true, nullable:true)
hairColor (blank:true, nullable:true)
smoke (blank:true, nullable:true)
drink (blank:true, nullable:true)
heightFeet (blank:true, nullable:true, validator: { value ->
if (value != null && (value < 3 || value > 7)) {
return 'applicant.invalid.heightFeet'
}
})
heightInches (blank:true, nullable:true, validator: { value ->
if (value != null && (value < 1 || value > 12)) {
return 'applicant.invalid.heightInches'
}
})
}
}
向导是我的控制器。有一个操作来处理表单请求,该请求提交要填充到 LifestyleCommand 对象中的数据。我只是在没有填写任何字段的情况下提交页面,所以所有内容都是有效的空/空。
我正在运行 grails 2.2.4