2017-12-27 25 views
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); 
    } 
}); 

答えて

0

Vaadin 8はGridTreeGrid又はComboBoxなど項目コンポーネントのDataProvider Sを使用します。 setItemsメソッドは、配列/コレクションをコンボボックスにListDataProviderに設定する便利な方法です。そのため、ListDataProviderにキャストしてgetItemsに電話をかけてgetDataProviderに電話することができます(javaのドキュメントhereを参照)。

+0

ありがとうございました。 –

関連する問題