Grails g:选择自动完成

发布于 2024-08-16 18:57:23 字数 427 浏览 3 评论 0原文

我已将 ag:select 字段更改为 yui 自动完成(不使用 yui 插件),现在我得到:

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

println 控制器中的参数在两种情况下看起来相同。

我可以继续使用参数中的字符串 id 并获取所需的域对象,但我想使用活页夹。

我猜这是 binder 的工作方式,但找不到问题。

是否可以像使用 g:select 时那样使用 ID 绑定对象?

谢谢, 盖伊

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌枕肩 2024-08-23 18:57:23

问题是 select 的名称可能类似于 property.id ,Binder 会尝试根据 id(是一个 int)查找对象,并且不能将其转换为字符串。

您可能需要更改 name 属性并编写代码来“取消引用”参数,使用类似 findByName 的内容来查找要分配的对象,即

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

确保新名称与现有属性不同类,否则 Binder 将尝试将字符串分配给属性。除非你的属性是一个字符串......

希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文