Vaadin beanItemContainer 属性 is array: 如何从数组中获取数据
Vaadin beanItemContainer property is array: how to get the data from the array
我想从数组中获取数据到 vaadin 网格中。
以下是我的代码的一些相关部分:
来自网格的 builder-class
Grid grid = new Grid();
for(int i = 0; i<numberColumns; i++){
String propertyId = "deliveryList[" + i + "]";
grid.addColumn(propertyId);
}
在基地class:
public class DeliveryVO {
private Integer[] deliveryList;
public Integer[] getDeliveryList() {
return deliveryList;
}
...
并在应显示网格的视图中:
DeliveryVO deliveryVO1 = new deliveryVO(12);
final BeanItemContainer<DeliveryVO> beanItemContainer = new BeanItemContainer<DeliveryVO>(DeliveryVO.class);
beanItemContainer.addBean(deliveryVO1);
final Grid grid = new xGrid.Builder()
.setNumberColumns(12)
.setTimeGroup(TIME_GROUP.HOURLY).build();
grid.setContainerDataSource(beanItemContainer);
...
addComponent(grid);
当我尝试 运行 时,出现以下错误:
java.lang.IllegalStateException:在 Grid 中找到至少一列在给定容器中不存在:deliveryList[0] with the header "Delivery List[0]"
当我在 de DeliveryVO-class 中使用属性的 propertyId 时,我可以在网格中获取数据,但是我无法访问数组中的数据...有人可以帮助我们获取这个 array-data进入网格?
当使用 BeanItemContainer 时,它希望列是容器的 VO 或 bean class 的属性。在您的情况下,最好的选择是使用列生成器,您可以在其中编写从数组值中提取和构建列组件的特定逻辑。或者,您可以编写自己的扩展 BeanItemContainer 的容器,然后覆盖数据提取逻辑的 getContainerValue 方法。
可以在以下位置找到此问题的答案:
我想从数组中获取数据到 vaadin 网格中。 以下是我的代码的一些相关部分:
来自网格的 builder-class
Grid grid = new Grid();
for(int i = 0; i<numberColumns; i++){
String propertyId = "deliveryList[" + i + "]";
grid.addColumn(propertyId);
}
在基地class:
public class DeliveryVO {
private Integer[] deliveryList;
public Integer[] getDeliveryList() {
return deliveryList;
}
...
并在应显示网格的视图中:
DeliveryVO deliveryVO1 = new deliveryVO(12);
final BeanItemContainer<DeliveryVO> beanItemContainer = new BeanItemContainer<DeliveryVO>(DeliveryVO.class);
beanItemContainer.addBean(deliveryVO1);
final Grid grid = new xGrid.Builder()
.setNumberColumns(12)
.setTimeGroup(TIME_GROUP.HOURLY).build();
grid.setContainerDataSource(beanItemContainer);
...
addComponent(grid);
当我尝试 运行 时,出现以下错误:
java.lang.IllegalStateException:在 Grid 中找到至少一列在给定容器中不存在:deliveryList[0] with the header "Delivery List[0]"
当我在 de DeliveryVO-class 中使用属性的 propertyId 时,我可以在网格中获取数据,但是我无法访问数组中的数据...有人可以帮助我们获取这个 array-data进入网格?
当使用 BeanItemContainer 时,它希望列是容器的 VO 或 bean class 的属性。在您的情况下,最好的选择是使用列生成器,您可以在其中编写从数组值中提取和构建列组件的特定逻辑。或者,您可以编写自己的扩展 BeanItemContainer 的容器,然后覆盖数据提取逻辑的 getContainerValue 方法。
可以在以下位置找到此问题的答案: