在Vaadin 7中以编程方式选择网格中的行?

在Vaadin 7中以编程方式选择网格中的行?,vaadin,vaadin7,vaadin-grid,Vaadin,Vaadin7,Vaadin Grid,在7.5.3中的小部件中,我们可以通过调用或来确定当前选择的行 那么我们如何以编程方式设置选择?Setter方法缺少bug? 瓦丁的书中提到了setter方法Grid::setSelectedRows以及getter 当前选定的行可以通过项目ID集合使用setSelectedRows设置,并使用getSelectedRows读取 但是,网格类文档没有列出该方法。NetBeans 8.0.2在其auto complete中也没有建议使用该方法 显然是一只虫子。请参阅Ticket.的官方文档中确实没

在7.5.3中的小部件中,我们可以通过调用或来确定当前选择的行

那么我们如何以编程方式设置选择?

Setter方法缺少bug? 瓦丁的书中提到了setter方法Grid::setSelectedRows以及getter

当前选定的行可以通过项目ID集合使用setSelectedRows设置,并使用getSelectedRows读取

但是,网格类文档没有列出该方法。NetBeans 8.0.2在其auto complete中也没有建议使用该方法


显然是一只虫子。请参阅Ticket.

的官方文档中确实没有说明此方法,但您仍然可以通过编程来实现。我不会争论它是否是一个bug。首先,你需要知道你的选择模式是什么。然后可以选择一行或多行:

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    Customer c = new Customer(1);
    container = new BeanItemContainer<>(Customer.class, Arrays.asList(c, new Customer(2)));
    grid = new Grid(container);
    grid.setSelectionMode(SelectionMode.SINGLE);
    SingleSelectionModel m  = (SingleSelectionModel) grid.getSelectionModel();
    m.select(c);
    layout.addComponents(grid);
    setContent(layout);
}

在我的案例7.5.6中,较新的Vaadin直接在网格中使用selectObject方法

例如:

Grid grid = new Grid(container);
grid.setSelectionMode(Grid.SelectionMode.SINGLE);
grid.select(row);

例如,行对象可以取自SelectionListener事件,也可以取自@kukis answer中的added before对象。

您是否检查过setSelectedRows是否如本书中所述可用@muenzpraeger不,不,不,不,不,不。它也不会出现在我的NetBeans自动完成中。谢谢你在《瓦丁之书》中引用这一点。我提交了一份虫子报告,票。