如何使用Grails从一个视图保存多个对象
这个问题是本帖的后续问题 该示例建议在运行时不工作并引发以下异常如何使用Grails从一个视图保存多个对象,grails,gorm,one-to-many,Grails,Gorm,One To Many,这个问题是本帖的后续问题 该示例建议在运行时不工作并引发以下异常 null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs). Stacktrace follows: Message: null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs) Line |
null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs). Stacktrace follows:
Message: null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs)
Line | Method
->> 43 | doCall in blog.omarello.ContactController$_closure4$$ENLORkU6
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . in ''
^ 662 | run in java.lang.Thread
我认为,任何人都可以帮助我理解如何创建一个GSP,它可以让我保存同一个域类的多个实例,而不是让示例工作。例如,一个GSP可以让我一次插入多个图书实例?再次检查我链接的项目。这是一个示范的一些更好的做法之一,这样做。特别是,请查看,因为这是视图的外观。实际的保存块在中完成,由使用。这个项目正是你想要做的。查看它。如下更改电话示例中的Contact类,它应该可以正常工作
package blog.omarello
import org.apache.commons.collections.list.LazyList;
import org.apache.commons.collections.FactoryUtils;
class Contact {
static constraints = {
firstName(blank:false)
lastName(blank:false)
}
String firstName
String lastName
String nickName
List phones = LazyList.decorate(new ArrayList(),
FactoryUtils.instantiateFactory(Phone.class));
// List phones = new ArrayList()
static hasMany = [ phones:Phone ]
static mapping = {
phones cascade:"all-delete-orphan"
}
// def getPhonesList() {
// return LazyList.decorate(
// phones,
// FactoryUtils.instantiateFactory(Phone.class))
// }
def String toString() {
return "${lastName}, ${firstName}"
}
}