Grails:惰性列表的问题
我有一个网页,允许用户输入数据,当存储到我的数据库时,这些数据将形成主/详细关系。我将数据提交给Grails控制器,该控制器将数据绑定到命令对象。由于我不知道将提交多少“详细信息”行,因此我尝试使用惰性列表将详细信息数据绑定到。我失败得惊人 我的命令对象看起来像:Grails:惰性列表的问题,grails,master-detail,Grails,Master Detail,我有一个网页,允许用户输入数据,当存储到我的数据库时,这些数据将形成主/详细关系。我将数据提交给Grails控制器,该控制器将数据绑定到命令对象。由于我不知道将提交多少“详细信息”行,因此我尝试使用惰性列表将详细信息数据绑定到。我失败得惊人 我的命令对象看起来像: String title List testItems = LazyList.decorate(new ArrayList(), FactoryUtils.
String title
List testItems = LazyList.decorate(new ArrayList(),
FactoryUtils.instantiateFactory(VocabQuestion.class));
当我提交表格时,我得到以下例外情况:
| Error 2013-06-04 22:42:54,068 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - MissingMethodException occurred when processing request: [POST] /*****/vocabulary/save - parameters:
testItems[1].question: Q2
title: Test
testItems[0].answer: A1
testItems[0].question: Q1
testItems[0].vocabulary_test_id:
testItems[1].answer: A2
create: Create
No signature of method: vocabularytest.TestCreationCommand.propertyMissing() is applicable for argument types: () values: []
Possible solutions: propertyMissing(java.lang.String). Stacktrace follows:
Message: No signature of method: vocabularytest.TestCreationCommand.propertyMissing() is applicable for argument types: () values: []
Possible solutions: propertyMissing(java.lang.String)
Line | Method
->> 102 | <init> in vocabularytest.TestCreationCommand
并且只需提交表单中的一条详细记录,那么一切都会按预期进行
我哪里做错了
编辑
我的VocabQuestion域类是
package vocabularytest
class VocabQuestion {
static constraints = {
}
static belongsTo = [vocabularyTest: VocabularyTest]
String question
String answer
}
我找到了一个答案(可能不是答案,但它是有效的)
我使用了LazyList语法,它在以后的Groovy版本中是本机的,如下所示
List testItems = [].withLazyDefault {new VocabQuestion()}
你能分享
VocabQuestion
定义吗。
List testItems = [].withLazyDefault {new VocabQuestion()}