我正在使用Vaadin-7设计器创建一个网格,它应该包含几个列,其中一些列不是字符串。
当我尝试添加一个包含非字符串元素的Row时,我得到了错误:
java.lang.IllegalArgumentException: Parameter 0(4711) is not an instance of java.lang.String
at com.vaadin.ui.Grid.addRow(Grid.java:6821)如何向Grid提供该列应为Integer的信息?
由于我对构造函数(它由设计者调用)没有影响,所以我需要一个不使用它的解决方案(或者展示如何将新对象应用到设计器或类似的地方)
发布于 2019-01-21 17:36:39
如果您有权访问网格,则可以尝试定义Integer列,如下所示:
grid.addColumn("Column_Name", Integer.class);您必须在使用网格(添加行)之前执行此操作。
另一种方法是使用BeanItemContainer。这段代码来自grid for the grid:
// 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
祝好运!
https://stackoverflow.com/questions/54286944
复制相似问题