【发布时间】:2016-05-11 11:43:29
【问题描述】:
我目前正在开发一个 grails 应用程序(版本 3.1.2),我遇到了一个目前无法解决的令人沮丧的错误。
举个例子:
// Domain classes
class RootBean {
NestedBean nestedBean
}
class NestedBean {
int nestedInteger
}
没什么好说的,只是一对一的关系,没有反向引用
现在让我们来说明我的问题:我有一个创建和一个编辑视图,它们都使用所有可能的输入来呈现一个编辑模板。使用新对象(创建)一切正常,但使用我想更新的现有对象,我收到此 GSP 错误消息:
URI
/VMPMessung/edit/2
Class
groovy.lang.MissingPropertyException
Message
Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/rootBean/edit.gsp:13] Error executing tag <g:render>: [views/rootBean/_editTemplate.gsp:1] Error executing tag <g:form>: [views/rootBean/_editTemplate.gsp:150] Error executing tag <f:widget>: No such property: nestedInteger for class: RootBean
Caused by
No such property: nestedInteger for class: RootBean
普惠制代码:
<f:widget class="form-control"
property="nestedBean.nestedInteger"
bean="RootBean"/>
我还通过 Taglibary 进行了调试,发现它出错的原因是类型整数,我在真实对象中得到了其他字符串字段,它们工作正常。在569 行的FormFieldsTagLib 类中抛出错误
private CharSequence renderNumericInput(BeanPropertyAccessor propertyAccessor,Map model, Map attrs) {
if (!attrs.type && model.constraints?.inList) {
attrs.from = model.constraints.inList
if (!model.required) attrs.noSelection = ["": ""]
return g.select(attrs)
} else if (model.constraints?.range) {
attrs.type = attrs.type ?: "range"
attrs.min = model.constraints.range.from
attrs.max = model.constraints.range.to
} else {
attrs.type = attrs.type ?: getDefaultNumberType(model )
if (model.constraints?.scale != null) attrs.step = "0.${'0' * (model.constraints.scale - 1)}1"
if (model.constraints?.min != null) attrs.min = model.constraints.min
if (model.constraints?.max != null) attrs.max = model.constraints.max
}
if(propertyAccessor != null && attrs.value) {
attrs.value = g.fieldValue(bean: propertyAccessor.rootBean, field: propertyAccessor.propertyName)
// This call causes the Error
// Debugging Values: propertyAccessor.rootBean: RootBean,
// propertyAccessor.propertyName: nestedInteger
}
return g.field(attrs)
}
我猜他们试图在 RootBean 而不是 NestedBean 上找到 fieldName,但我做错了什么还是 Grails 方面的错误?
希望你们中的一些人知道这个问题的答案,这对我来说真的是一个障碍:(
【问题讨论】: