BioBier
BioBier

Reputation: 84

Grails Fields Plugin using field templates issue

unfortunatly I can't find any good example where use of the Grails fields plugin is made. WIthin my app I would like to have some field rendered as a different type like text area or later the CKE editor. My domain:

class Case {    
    String description
}

I've created a _input.gsp that is found by the plugin: INFO formfields.FormFieldsTemplateService - found template /patchCase/description/input

It contains:

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

However I get

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?

Can any one describe how to use the customisation of fields or give a link with a good description (plugin doc is very thin)?

I'm on Grails 2.4.

Upvotes: 1

Views: 1308

Answers (2)

I've been through the same issue. Try to use bean="${class}" instead of bean="class". On "class" put the name of the class that you are trying to bean

Upvotes: 0

D&#243;nal
D&#243;nal

Reputation: 187499

I think your problem is the bean="Case" attribute. It seems the fields plugin is trying to render properties of the String "Case" rather than an instance of the Case class.

You should instead pass either the model key name of a Case instance, or the instance itself to this attribute. I would guess either of the following might work: bean="case" or bean="${case}".

Here's a Grails app of mine that makes extensive use of the fields plugin. Some example fields plugin templates are here and here's a form that uses them.

You'll notice that in almost all cases, an input field is passed as the body of the f:field tag, e.g.

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

This could be expressed more concisely as:

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

Upvotes: 4

Related Questions