java - 创建后如何设置 Vaadin7 Grid 的 DataType
问题描述
我正在使用 Vaadin-7 设计器创建一个应该包含几列的网格,其中一些不是字符串。
当我尝试添加包含非字符串元素的行时,出现错误:
java.lang.IllegalArgumentException: Parameter 0(4711) is not an instance of java.lang.String
at com.vaadin.ui.Grid.addRow(Grid.java:6821)
如何向 Grid 提供 Column 应为 Integer 的信息?
由于我对构造函数没有影响(由设计师调用),我需要一个不使用的解决方案(或展示如何将新对象应用于设计师或之后的类似对象)
解决方案
如果您有权访问网格,则可以尝试像这样定义 Integer 列:
grid.addColumn("Column_Name", Integer.class);
您必须在使用网格(添加行)之前执行此操作。
另一种方法是使用 BeanItemContainer。来自网格的 Vadding 文档的这段代码:
// Have some data
Collection<Person> people = Lists.newArrayList(
new Person("Nicolaus Copernicus", 1543),
new Person("Galileo Galilei", 1564),
new Person("Johannes Kepler", 1571));
// Have a container of some type to contain the data
BeanItemContainer<Person> container =
new BeanItemContainer<Person>(Person.class, people);
// Create a grid bound to the container
Grid grid = new Grid(container);
grid.setColumnOrder("name", "born");
layout.addComponent(grid);
欲了解更多信息: https ://vaadin.com/docs/v7/framework/components/components-grid.html
祝你好运!
推荐阅读
- html - css - 并排对齐 3 个不同大小的 div
- c# - C# 中的 Stackoverflow 异常
- python - 我怎么能叫这个类?
- java - 如何使用Java将mm-dd-yyyy(来自csv文件的数据)的格式更改为在MySql中存储为yyyy-mm-dd
- docker - kubernetes:从同一命名空间中的另一个 pod SSH 到一个 pod
- c# - System.Web.HttpCompileException:类型“<>”在未引用的程序集中定义
- bash - 在 oneliner 的后台运行命令
- apache - drupal 7中的Apachesolr子查询错误
- java - 如何使用蓝牙从设备接收一些字节?
- vba - 如何循环这个索引匹配?