2010-04-08 50 views
0

http://n4.nabble.com/Grails-Data-Binding-for-One-To-Many-Relationships-with-REST-tp1754571p1754571.html所述,我试图自动绑定我的REST数据。Grails数据绑定中的黑魔法?

我现在明白了一个-to-many关联所需的数据绑定必须有很多副作用的IDS,如清单地图:

[propName: propValue, manyAssoc: [1, 2]] 

但是,我越来越这个例外

Executing action [save] of controller [com.example.DomainName] caused exception: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.example.DomainName.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.example.DomainName.id 

但是,即使是weirder是为控制器生成的更新操作。在那里,我们有数据绑定这样的:

domainObjectInstance.properties = params['domainObject'] 

但是,这真的是个奇怪的东西,则params [“domainObject的”]为空!它是null,因为所有的domainObject字段都直接在params映射本身中传递。如果我将上述行更改为

domainObjectInstance.properties = null 

domainObject仍然更新!为什么会出现这种情况,更重要的是,我怎么能自动绑定我的传入XML如果它以这种格式(问题是一个-to-many关联):

<product> 
    <name>Table</name> 
    <brand id="1" /> 
    <categories> 
    <category id="1" /> 
    <category id="2" /> 
    </categories> 
</product> 

回答

0

这不是从你的例子100%清晰 - 当你尝试绑定时,你的“参数”的内容到底是什么。

如果你没有“domainObject.xxx = YYY”后的参数定义,那么什么都不会在PARAMS [“domainObject的”]。命名空间一样,是不是在大多数情况下,必要的,而且所需的表单字段使用前缀。

我猜你的数据在即将到来的 “XXX = YYY” 而不是 “domainObject.xxx = YYY”。

而且,我不知道是[1,2]消协是正确的要么。当然应该是[id:1,id:2]?