简体   繁体   中英

How do you use a String array as a member field in a Grails domain?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM