【问题标题】:Vaadin set selected row of tableVaadin 设置表格的选定行
【发布时间】:2016-07-11 03:47:19
【问题描述】:

Vaadin:我需要在更新表格内容后设置选定的行。 我有一个包含不同客户的组合框按钮。 另外我有两个表,第一个显示主要类别,第二个显示子类别。 最初,未选择客户,显示主要类别,未显示子类别。

当我点击一个类别时(比如说产品!),子类别表出现并显示子类别。 当我现在将客户从空更改为特定客户时,两个表都被过滤了,但是:产品选择丢失了。我需要将选择设置为之前选择的那个。

我从另一个类中获取表内容作为 sql-container 对象。

mainCatTable = new Table();
...
mainCatTable.setContainerDataSource(source.getMainCats());

//My Checkboxbutton
Combobox custBox = new ComboBox();

//Get the customers from the Database
custBox.setContainerDataSource(source.getCustomers());

custBox.setItemCaptionPropertyId("Customers");
custBox.addValueChangeListener(new ValueChangeListener() {
     public void valueChange(ValueChangeEvent valueEvent) {  

//Here I need to store the old selection, before i update the mainCat table to a specific customer  
          mainCatTable.setContainerDataSource(source.getMainCats(currentCustomer));

//Here I need something to set the selected row to the previous value
          subCatTable.setContainerDataSource(source.getSubCats());
          }
});

getMainCats 方法返回的 sql-container 是这样创建的:

FreeformQuery subcatExtractionQuery = new FreeformQuery("select customerName from customers", connectionPool);
return new SQLContainer(subcatExtractionQuery);

问题是,尝试了不同的方法,但没有奏效。 这是我的尝试: https://vaadin.com/forum/#!/thread/1819417/1819416 但他们使用索引容器,但我没有。

谁能解释在没有索引容器的情况下如何做到这一点?

【问题讨论】:

  • 那个“非索引容器”是什么样的控制器?你能说得更具体一点吗?
  • 对不起,现在我添加了信息。这是你的意思吗?

标签: java select vaadin vaadin7


【解决方案1】:

如何使用表的值来获取/设置“选定”行?

Object value = mainCatTable.getValue();    
mainCatTable.setContainerDataSource(source.getMainCats(currentCustomer));
mainCatTable.setValue(value);

【讨论】:

  • 我尝试了类似的方法,但没有成功。这行得通 - 谢谢!
  • 更新:不幸的是,这并不总是带来正确的选择。因为它只需要id。如果在更新前选择了第 3 行,则更新后选择了第 3 行。但是:内容可能会发生变化(例如:第一行出现新的 Maincat => 选择的旧 Maincat 现在位于第 4 行,在更新前位于第 3 行),因此在表格之后选择了另一个 mainCat更新。所以我需要一些可以读取选定的线/字符串(这对我来说没问题)和一个不通过 id 设置行,而是将其设置为特定字符串的 SETVALUE。
猜你喜欢
  • 1970-01-01
  • 2013-07-08
  • 1970-01-01
  • 2022-12-17
  • 1970-01-01
  • 1970-01-01
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多