创建Vaadin7网格后如何设置其数据类型

时间:2019-01-21 09:33:09

标签: java vaadin vaadin7 vaadin-grid

我正在使用Vaadin-7设计器创建一个网格,该网格应包含几列,其中有些不是String。

当我尝试添加包含非字符串元素的行时,出现错误:

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的信息?

由于我对构造函数没有任何影响(设计者将其调用),因此我需要一个不使用解决方案的解决方案(或说明如何将新对象应用于设计者或类似的对象)

1 个答案:

答案 0 :(得分:1)

如果您有权访问网格,则可以尝试定义如下的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

祝你好运!

相关问题