开发者

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

开发者 https://www.devze.com 2022-12-19 19:47 出处:网络
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 s

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? 开发者_Python百科


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号