[英]How to get item size in Vaadin8 combobox?
I'm trying to show a pop-up if there is no any item in Vaadin8 combobox. 如果Vaadin8组合框中没有任何项目,我想显示一个弹出窗口。 But there is no getItems() or size() methods.
但是没有getItems()或size()方法。
here is my code, if branch size = 0 I want to push a notification to user. 这是我的代码,如果分支大小= 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);
}
});
Vaadin 8 uses DataProvider
s for item components like Grid
, TreeGrid
or ComboBox
. Vaadin 8将
DataProvider
用于项目组件,例如Grid
, TreeGrid
或ComboBox
。 The setItems
method is a convenience method to set a ListDataProvider
with your array/collection to the combo box. setItems
方法是一种方便的方法,用于将具有数组/集合的ListDataProvider
设置为组合框。 Therefore, you can call getDataProvider
, cast to ListDataProvider
and call getItems
(see java doc here ). 因此,您可以调用
getDataProvider
,将其getDataProvider
为ListDataProvider
并调用getItems
(请参阅java doc here )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.