tags:

views:

318

answers:

1

I've changed a g:select field to a yui autocomplete (without using the yui plugin) and now I'm getting:

Failed to convert property value of type [java.lang.String] to required type...  

println the params in the controller looks identical in both cases.

I can go ahead and use the String id in the params and get the required domain object but I'd like to use the binder.

I guess its the way the binder works but couldn't find the problem.

Is it possible to get it to bind the object using the ID as done when using g:select ?

Thanks, Guy

+1  A: 

The problem is that the name of the select is probably something like property.id and Binder will try and lookup the object basesd on the id (which is an int) and this cannot be converted to a String.

You may need to change the name attribute and write code to "dereference" the parameter using something like findByName to find the object to assign ie

def propValue = Lookup.findByName(params.propertyName);
objectInstance.property = propValue;

Make sure the new name is not the same as an existing property of the class otherwise the Binder will try and assign the string to the property. Unless of cause your property is is a string....

Hope this helps.

Scott Warren