2013-06-04 57 views
0

我有一个网页,允许用户输入数据,当存储到我的数据库时,这些数据将形成主/从关系。我将数据提交给一个将数据绑定到Command对象的Grails控制器。因为我不知道要提交多少“明细”行,我试图使用懒惰列表来绑定详细数据。我惊人的失败。Grails:懒惰列表的问题

我的命令对象的样子:

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 

此异常情况很早就在对象的生命周期,presumeably如Grails的尝试将数据绑定到它。

如果我定义我的命令对象为:

String title  
List testItems = [new VocabQuestion()] 

只有从形式提交1个详细记录,按预期工作,然后一切。

我哪里错了?

编辑 我VocabQuestion域类是

package vocabularytest 
class VocabQuestion { 

    static constraints = { 

    } 

    static belongsTo = [vocabularyTest: VocabularyTest] 

    String question 
    String answer 

} 
+0

你能分享'VocabQuestion'的定义。 –

回答

1

我找到了答案(可能不是答案,但它的工作原理)

我用LazyList语法,在以后的Groovy版本本土如下。

List testItems = [].withLazyDefault {new VocabQuestion()}