我想知道如何根据我在另一个表中单击的内容过滤一个表。例如,如果我在国家表中单击俄罗斯,它应该在名称表中过滤所有来自俄罗斯的人。我想知道如何使用vaadin做到这一点。我在下面添加了一些相关代码。当我单击一个国家时,国家表应该过滤名称表。
这是我的过滤器方法:
public class CountryFilter implements Filter {
public String needle;
public CountryFilter(String needle) {
this.needle = needle;
}
public boolean appliesToProperty(Object id) {
return true;
}
public boolean passesFilter(Object itemId, Item item) {
String haystack = ("" + item.getItemProperty(Name) +
item.getItemProperty(Country)).toLowerCase();
return haystack.contains(needle);
}
}
下面是我使用过滤器
的搜索方法 public void initCountrySearch() {
country.setSelectable(true);
country.setImmediate(true);
name.setVisibleColumns(new String[] {"name"});
country.setVisibleColumns(new String[] {"country"});
country.addValueChangeListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// TODO Auto-generated method stub
data.name.removeAllContainerFilters();
data.name.addContainerFilter(new CountryFilter(event.getProperty().getValue().toString()));
}
});
}
您可以在选择标准表上设置ValueChangeListener,它通知您值的更改。在值更改方法中,您可以获得选定的项,并根据该项在目标表上进行加载。