【问题标题】:Grails GSP: <g:widget ... /> throws no such property on nested NumbersGrails GSP:<g:widget ... /> 在嵌套数字上不抛出此类属性
【发布时间】: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 方面的错误?

希望你们中的一些人知道这个问题的答案,这对我来说真的是一个障碍:(

【问题讨论】:

    标签: grails groovy gsp


    【解决方案1】:

    我有同样的问题,奇怪的是我没有问题,我只有在

    我可以通过一种解决方法来解决它,在 RootBean 类中实现一个用于嵌套整数的 getter:

    def int getNumber() {
        return nestedBean?.nestedInteger
    }
    

    这对我有用。 能不能好好解决?

    【讨论】:

    • 嘿,谢谢你的提示,我明天早上试试。我会告诉你的
    • 嗯,这对我也有效。还没有找到其他解决方案:/ 我想这不值得努力
    • 我很高兴它对你有用@dennis-bukowski!我想也是一样,也许我们应该就此提出一个问题。在我看来,如果这是一个问题,它必须在 Grails 的未来版本中得到解决。
    猜你喜欢
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2016-08-27
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多