作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用特定的对象列表在编辑器中实现 GWT ValueListBox,我的代码:
...
@UiField(provided = true)
@Path("address.countryCode")
ValueListBox<Country> countries = new ValueListBox<Country>(
new Renderer<Country>() {
@Override
public String render(Country object) {
return object.getCountryName();
}
@Override
public void render(Country object, Appendable appendable)
throws IOException {
render(object);
}
},
new ProvidesKey<Country>() {
@Override
public Object getKey(Country item) {
return item.getCountryCode();
}
});
...
乡村类
public class Country {
private String countryName;
private String countryCode;
}
但是,在 GWT 编译期间,我收到此错误:
Type mismatch: cannot convert from String to Country
最佳答案
问题是您正在尝试使用Country
编辑器编辑address.countryCode
(查看路径注释)。要实现此目的,您应该将路径更改为 address.country
并在 editorDriver.flash()
之后分配 address.countryCode
。像这样的东西:
Address address = editorDriver.flush();
address.setCountryCode(address.getCountry().getCountryCode());
为了支持这一点,Address 类应该将 Country 对象作为属性。
您可能假设 ValueListBox 将像经典的 select
一样工作,其中键被分配给属性。这里整个对象被分配。因此,在您的情况下 Country
对象不能分配给 address.countryCode
,反之亦然。
顺便说一句。您可以更正渲染器(如下面的代码)并在渲染器和 key 提供程序中将 null
对象作为参数处理。
new Renderer<Country>() {
...
@Override
public void render(Country object, Appendable appendable)
throws IOException {
appendable.append(render(object));
}
...
}
关于GWT ValueListBox、渲染器和 ProvidesKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10116154/
如何使用特定的对象列表在编辑器中实现 GWT ValueListBox,我的代码: ... @UiField(provided = true) @Path("address.countryCode")
我是一名优秀的程序员,十分优秀!