我有一个设计如下的问题域模型
class Question {
List<Choice> choiceCollection;
static hasMany = [choiceCollection:Choice]
static mappping = {
choiceCollection(joinTable:false)
}
}
为了满足我的需求,/grails-app/views/question/create.gsp 已定制,如下所示
创建.gsp
<g:each var="i" in="${(0..4)}">
<div class="fieldcontain required">
<label for="description">
Option ${i + 1}.
<span class="required-indicator">*</span>
</label>
<g:textArea name="choiceCollection[${i}].description" cols="40" rows="5" maxlength="2000" value="${questionInstance?.choiceCollection[i]?.description}"/>
</div>
</g:each>
当我尝试访问创建视图时,出现以下错误
Error evaluating expression [questionInstance?.choiceCollection[i]?.description]: Cannot invoke method getAt() on null object
问题:我应该怎么做才能运行我的应用程序?
Grails 版本:2.1.1