GWT 编辑器框架:下拉列表
我正在寻找有人为我指明正确的方向(链接)或提供代码示例,以使用 RequestFactory
和 Editor 实现多对一关系的下拉列表
框架。我的项目的一个模型具有多对一的关系:GWT
中的
@Entity
public class Book {
@ManyToOne
private Author author;
}
当我构建视图来添加/编辑一本书时,我想显示一个下拉列表,可用于选择哪位作者写了这本书。如何使用 Editor
框架来完成此操作?
I'm looking for someone to point me in the right direction (link) or provide a code example for implementing a drop down list for a many-to-one relationship using RequestFactory
and the Editor
framework in GWT
. One of the models for my project has a many to one relationship:
@Entity
public class Book {
@ManyToOne
private Author author;
}
When I build the view to add/edit a book, I want to show a drop down list that can be used to choose which author wrote the book. How can this be done with the Editor
framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于下拉列表,您需要一个
ValueListBox
,而它恰好是AuthorProxy
的编辑器,所以一切都很好。但随后您需要填充列表 (setAcceptableValues
),因此您可能必须向服务器发出请求来加载作者列表。请注意,
setAcceptableValues
会自动将当前值(由getValue
返回,默认为null
)添加到列表(以及setValue
)如果需要的话,code> 也会自动将该值添加到可接受值列表中),因此请确保将null
作为可接受的值传递,或者使用以下值调用setValue
调用之前的列表setAcceptableValues
。For the drop-down list, you need a
ValueListBox<AuthorProxy>
, and it happens to be an editor ofAuthorProxy
, so all is well. But you then need to populate the list (setAcceptableValues
), so you'll likely have to make a request to your server to load the list of authors.Beware the
setAcceptableValues
automatically adds the current value (returned bygetValue
, and defaults tonull
) to the list (andsetValue
automatically adds the value to the list of acceptable values too if needed), so make sure you passnull
as an acceptable value, or you callsetValue
with a value from the list before callingsetAcceptableValues
.我知道这是一个老问题,但无论如何,这是我的两分钱。
我在类似的情况下遇到了一些麻烦。问题在于,在
RequestContext
中检索到的可接受值(AuthorProxy
实例)与BookEditor
用于编辑的值不同BookProxy
。结果是,当我尝试编辑
BookProxy
对象时,当前的AuthorProxy
总是在ValueListBox
中重复。经过一番研究,我在 GWT Google 中发现了这篇文章小组,托马斯解释说因此,由于我无法更改编辑工作流程,因此我选择通过设置在比较中使用不同对象字段的自定义
ProvidesKey
来更改ValueListBox
处理其值的方式过程。我的最终解决方案与此类似:
这个解决方案对我来说似乎没问题。我希望它对其他人有帮助。
I know it's an old question but here's my two cents anyway.
I had some trouble with a similar scenario. The problem is that the acceptable values (
AuthorProxy
instances) were retrieved in aRequestContext
different than the one theBookEditor
used to edit aBookProxy
.The result is that the current
AuthorProxy
was always repeated in theValueListBox
when I tried to edit aBookProxy
object. After some research I found this post in the GWT Google group, where Thomas explained thatSo, as I could not change my editing workflow, I chose to change the way the
ValueListBox
handled its values by setting a customProvidesKey
that used a different object field in its comparison process.My final solution is similar to this:
This solution seems ok to me. I hope it helps someone else.