在 Wicket 中加载页面时在 ObjectAutoCompleteField 中显示最初选择的对象
我已按照 Wicket 示例指南 来让 ObjectAutoCompleteField 正常工作,并且它确实非常好。
不过,我有一个很大的问题,那就是在页面加载时在字段中显示初始设置的对象。该对象是从我用于使用 ObjectAutoCompleteField 的表单的模型中检索的。更改 ObjectAutoCompleteField 会更改它“连接”到的模型属性,并且该字段中的任何后续更改都会在其位置显示适当的标签,而不是页面加载时的初始标签 - 唯一显示的是编辑链接(到进入自动完成功能)。
我查看了 ObjectAutoCompleteBuilder 的文档,但没有找到任何相应的方法来在页面加载时显式设置初始值。
I've followed the Wicket by Example guide to get the ObjectAutoCompleteField working, and it does so quite nicely.
I have a huge problem, though, and that is to show an initially set object in the field when the page loads. The object is retrieved from a model I use for the form where the ObjectAutoCompleteField is used. Changing the ObjectAutoCompleteField changes the model attribute it is "connected" to, and any subsequent changes in the field shows the appropriate label in its place, just not the initial one when the page loads—the only thing that shows is the edit link (to get to the autocomplete functionality).
I've looked around in the documentation for the ObjectAutoCompleteBuilder but haven't found any corresponding method to even set the initial value explicitly on page load.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于通过查看与ObjectAutoCompleteField相关的类找到了解决方案。
ObjectAutoCompleteField是通过ObjectAutoCompleteBuilder中的build方法构造的。因此,通过调用构建器上的 readOnlyRenderer 方法,创建一个新的 ObjectReadOnlyRenderer 在其 getObjectRenderer 内创建一个标签,我得到了 ObjectAutoCompleteField 在页面加载时渲染预选的对象。
人们可能会认为这是标准行为,但现在我知道以供将来参考。
I finally managed to find a solution by looking through the classes relating to ObjectAutoCompleteField.
The ObjectAutoCompleteField is constructed by the build method in ObjectAutoCompleteBuilder. So, by calling the readOnlyRenderer method on the builder, creating a new ObjectReadOnlyRenderer creating a label inside its getObjectRenderer, I got the ObjectAutoCompleteField to render a preselected object on page load.
One would think that this was the standard behaviour, but now I know for future reference.