如果Vaadin8组合框中没有任何项目,我会尝试显示弹出窗口。但是没有getItems()或size()方法。
这是我的代码,如果分支大小=0,我想推送一个通知给用户。
cbxBranch = new ComboBox<>();
cbxBranch.setPlaceholder("Select a branch");
cbxBranch.setItemCaptionGenerator(Branch::getBranchName);
cbxBranch.setEmptySelectionAllowed(false);
cbxBranch.setItems(getBranches());
cbxBranch.addFocusListener(e -> {
//this line just a sample..
System.out.println(cbxBranch.getDataProvider().size());
});更新:
cbxBranch.addFocusListener(e -> {
if (((ListDataProvider<Branch>) cbxBranch.getDataProvider()).getItems().isEmpty()) {
Notification.show("You don't have a branch!", Type.WARNING_MESSAGE);
}
});发布于 2017-12-27 21:32:32
Vaadin8将DataProviders用于Grid、TreeGrid或ComboBox等项目组件。setItems方法是一种方便的方法,用于将数组/集合设置为组合框的ListDataProvider。因此,您可以调用getDataProvider,强制转换为ListDataProvider,然后调用getItems (参见java文档here)。
https://stackoverflow.com/questions/47992228
复制相似问题