tags:

views:

41

answers:

1

I'm trying to create a basic grails domain object and for one of the fields I want to use an array of Strings. However even after running grails generate-views I still don't see the ability to edit said array. Am I going about this wrong?

+3  A: 

If you run 'grails install-templates' you can edit src/templates/scaffolding/renderEditor.template which is where the HTML generation for editors is defined. Add in a new "else if" for String[]:

else if (property.type == String[].class)
    out << renderStringArrayEditor(domainClass, property)

and implement renderStringArrayEditor however you think best:

private renderStringArrayEditor(domainClass, property) {
...
}

I have no idea what HTML to use, but I might go with a textarea and split on \n. Whatever you decide on, you'll need to convert the input parameter to a String array in your controller methods.

If you're already run 'grails generate-all' or 'grails generate-views' you'll need to run 'grails generate-views' to regenerate your GSPs with the new editor.

Burt Beckwith
I think I'll try this out. It may be that I'm doing the wrong thing here, but hey, I'm still learning this framework. Thx.
BenCourliss
Turns out that I ended up not doing it this way, but rather taking Phillpe's advice. So I created a separate object that represents a "feature" and got it working. I really didn't want to mess with the renderEditor.template file, although now I understand a whole lot more about how Grails works on the backend.
BenCourliss