简体   繁体   中英

Grails g:select to autocomplete

I've changed ag: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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM