我正在使用 Vaadin-7 Designer 创建一个应包含多个列的网格,其中一些列不是字符串。
当我尝试添加包含非字符串元素的行时,出现错误:
java.lang.IllegalArgumentException: Parameter 0(4711) is not an instance of java.lang.String
at com.vaadin.ui.Grid.addRow(Grid.java:6821)
如何向网格提供列应为整数的信息?
由于我对构造函数(由设计器调用)没有影响力,因此我需要一种不使用构造函数的解决方案(或演示如何将新对象应用于设计器或随后的类似操作)
最佳答案
如果您有权访问网格,您可以尝试像这样定义整数列:
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
祝你好运!
关于java - 创建 Vaadin7 网格后如何设置其数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54286944/