开发者

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? 开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜