我有一个Grails模板_questionForm.gsp
。但是,此模板中未识别question
(Question
域类的属性)。可能是什么原因?
_questionForm.gsp
<g:form action="addQuestions" controller="dashboard" method="post">
<br/>
Question: <g:textArea name="question" required="required" value="${questionInstance?.question}"/> <br/> //.question not recognized here
<!--For Options-->
<g:each in="${(1..<5)}" var="i">
Option ${i} : <g:textField name="option${i}" required="required" class="options"/> <br/>
</g:each>
Subject: <g:select name="questionSubject"
from="${com.dwit.research.begnas.api.Subject.list()}"
optionValue="subject"
optionKey="id" noSelection="['':'Choose Subject']" required="required"/>
<br/><br/>
<em>Correct Answer: </em><br/>
<!--For correct answer-->
<g:each in="${(1..<5)}" var="i">
<input type="radio" name="correct_answer" value="${i}" id="rdo_option${i}"/> <label for="rdo_option${i}">Option ${i}</label><br/>
</g:each>
<br/>
<g:submitButton name="Next"/>
</g:form>
问题(域类)
package com.dwit.research.begnas.api
课堂问题{
String question
Boolean isSkipped = false
Subject subject
static constraints = {
}
}
答案 0 :(得分:0)
问题是您的questionInstance
变量设置为String
而不是Question
的实例。
_questionForm.gsp
的控制器。render()
方法调用来设置视图和模型。model.questionInstance
更改为Question
。