问题
I have two grails domain classes
Class MultipleChoiceQuestion {
String question
static constraints = {
...
}
static hasMany = [options:MultipleChoiceOption]
}
and
class MultipleChoiceOption{
String answerOption
boolean correctOption
MultipleChoiceQuestion question
static constraints = {
...
}
}
I want my users to be able to create a question then add atleast 3 options without navigating/clicking on different screens.
My first question is must I generate view and start editing code?
And if the answer to question above is yes then my second question is, what's the best way to save a question along with multiple options in one form submit? The generated code will have something like following for each option.
<g:textField name="answerOption" value="${answerOptionInstance?.answerOption}"/>
<g:checkBox name="correctOption" value="${answerOptionInstance?.correctOption}"/>
how can I have multiple such elements in one page? Please see the wireframe to get an idea of what I want to achieve, my apologies for poorly created wire frame. Click on the link for opening the image in your browser http://cynosuredev.com/wf.png

回答1:
maybe this site will help you http://omarello.com/2010/08/grails-one-to-many-dynamic-forms/
回答2:
You don't have to use Grails scaffolding if you don't want to. Since this is a pretty specialized form, you should construct the HTML yourself. I've created a test project at github that shows a good design for this problem. Check it out.
来源:https://stackoverflow.com/questions/8758232/grails-one-to-many-relationship-view