【问题标题】:Grails Fields Plugin using field templates issueGrails Fields Plugin 使用字段模板问题
【发布时间】:2014-11-21 11:29:57
【问题描述】:

不幸的是,我找不到任何使用 Grails 字段插件的好例子。 在我的应用程序中,我希望将某些字段呈现为不同类型,如文本区域或稍后的 CKE 编辑器。我的域名:

class Case {    
    String description
}

我创建了一个插件可以找到的 _input.gsp: INFO formfields.FormFieldsTemplateService - 找到模板 /patchCase/description/input

它包含:

<f:field  bean="Case" property="description">
  <g:textArea name="description" cols="40" rows="5" maxlength="5000" value="some default text"/>
</f:field>

但是我得到了

ERROR errors.GrailsExceptionResolver  - NotReadablePropertyException occurred when processing request: [GET] /M3PatchManage/patchCase/create
Invalid property 'description' of bean class [java.lang.String]: Bean property 'description' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?. Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <g:form>: Error executing tag <f:all>: Error executing tag <f:field>: Invalid property 'description' of bean class [java.lang.String]: Bean property 'description' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

谁能描述一下如何使用字段的自定义或者给出一个描述好的链接(插件文档很薄)?

我正在使用 Grails 2.4。

【问题讨论】:

    标签: templates grails plugins field


    【解决方案1】:

    我认为你的问题是bean="Case" 属性。似乎字段插件正在尝试呈现字符串 "Case" 的属性,而不是 Case 类的实例。

    您应该将Case 实例的模型键名称或实例本身传递给此属性。我猜以下任何一个都可能有效:bean="case"bean="${case}"

    这里是a Grails app of mine,它广泛使用了字段插件。一些示例字段插件模板是here,这是使用它们的a form

    您会注意到,在几乎所有情况下,输入字段都会作为 f:field 标记的主体传递,例如

    <f:field bean="competition" property="code" label="Code">
      <g:textField name="${property}" value="${value}" class="input-xlarge" maxlength="191"/>
    </f:field>
    

    这可以更简洁地表达为:

    <f:field bean="competition" property="code" label="Code" 
            input-class="input-xlarge" input-maxlength="191"/>
    

    【讨论】:

    • 谢谢!在 _input.gsp 中有 现在可以使用了!
    • 正如我上面解释的,你应该尽量避免将输入字段的标记添加到&lt;f:field&gt;的正文中
    【解决方案2】:

    我也遇到过同样的问题。尝试使用 bean="${class}" 而不是 bean="class"。 在“类”上输入您要创建的类的名称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      相关资源
      最近更新 更多