Black Magic in Grails Data Binding!?
Posted
by Tiago Alves
on Stack Overflow
See other posts from Stack Overflow
or by Tiago Alves
Published on 2010-04-08T11:18:06Z
Indexed on
2010/04/08
11:23 UTC
Read the original article
Hit count: 209
As described in http://n4.nabble.com/Grails-Data-Binding-for-One-To-Many-Relationships-with-REST-tp1754571p1754571.html i'm trying to automatically bind my REST data.
I understand now that for one-to-many associations the map that is required for the data binding must have a list of ids of the many side such as:
[propName: propValue, manyAssoc: [1, 2]]
However, I'm getting this exception
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
However, even weirder is the update action that is generated for the controller. There we have the databinding like this:
domainObjectInstance.properties = params['domainObject']
But, and this is the really weird thing, params['domainObject'] is null! It is null because all the domainObject fields are passed directly in the params map itself. If I change the above line to
domainObjectInstance.properties = null
the domainObject is still updated! Why is this happening and more important, how can I bind my incoming XML automatically if it comes in this format (the problem is the one-to-many associations):
<product>
<name>Table</name>
<brand id="1" />
<categories>
<category id="1" />
<category id="2" />
</categories>
</product>
© Stack Overflow or respective owner