1
我试图显示一个弹出窗口,如果Vaadin8组合框中没有任何项目。但是没有getItems()或size()方法。如何获取Vaadin8组合框中的项目大小?
这是我的代码,如果分支大小= 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());
});
UPDATE:
cbxBranch.addFocusListener(e -> {
if (((ListDataProvider<Branch>) cbxBranch.getDataProvider()).getItems().isEmpty()) {
Notification.show("You don't have a branch!", Type.WARNING_MESSAGE);
}
});
非常感谢你,它工作正常! –