I am new to grails and I have an app with this simple classes:
class Person{
String name
}
class Voter{
String voteAddress
String counter
Person person
}
Now, I am trying to update the field person only of the Voter class. Now I have code below and it is not working and I know it is wrong but I tried it anyway:
def updatePersonFieldOnly{
def voterInstance = Voter.get(params.id)
voterInstance.properties=params
def personInstance = Voter.findById(12)
voterInstance.person = personInstance
......some other code to update
.....
}
Now, when the action executes, I got this error:
Failed to convert property value of type java.lang.String to required type proj.Person for property person; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [proj.Person] for property person: no matching editors or conversion strategy found
I am still on my way on reading the docs of grails. So can anyone help me about this? Thanks.
It looks like you have a property called “person” in the params map that Grails is trying to convert to the “Person” object. Try changing that field to “person.id” and Grails should automatically fetch the Person object corresponding to that id and match it to the “person” object.
Refer to DataBinding under the section “Data binding and Single-ended Associations” for more information.