2010-04-08 55 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]?