Below you will find a second example, which I use to open a dialog with a listbox in it.
After selecting a value out of listbox I transfer and use it in the underlying form:
private void btEditL1_onClick(final ClickEvent<Button> event)
{
//modal Dialog Mainclassification
final HorizontalLayout horlayout=new HorizontalLayout();
final VerticalLayout vertlayout=new VerticalLayout();
final Notification MyL1Selection=new Notification();//
final Button btnAbbruch=new Button();
final ComboBox<TfinGroup> cBL1Liste = new ComboBox<>();
btnAbbruch.setText("Abbruch");
vertlayout.add(new Label("Bitte wählen Sie eine Klasse?"));
horlayout.add(cBL1Liste);
horlayout.add(btnAbbruch);
vertlayout.add(horlayout);
cBL1Liste.setDataProvider(DataProvider.ofCollection(TfinGroupDAO.INSTANCE.findMainGroups()));
cBL1Liste.setItemLabelGenerator(ItemLabelGeneratorFactory
.NonNull(v -> CaptionUtils.resolveCaption(v, "{%id}, {%groupName}")));
cBL1Liste.addValueChangeListener(evtChangeSelektion ->
{
this.logger.info("Es wurde ein Wert aus der Liste selektiert: "+ evtChangeSelektion.getValue().getId());
// muss zu cB2 übergeben werden und in Textfeld nrL1Id
this.nrL1Id.setValue((double)evtChangeSelektion.getValue().getId());
MyL1Selection.close();
});
btnAbbruch.addClickListener(evtclose->
{
this.logger.info("Abbrechen geklickt");
MyL1Selection.close();
});
vertlayout.add(horlayout);
horlayout.add(btnAbbruch);
MyL1Selection.add(vertlayout);
MyL1Selection.setPosition(Position.MIDDLE);
MyL1Selection.addThemeVariants(NotificationVariant.LUMO_PRIMARY);
MyL1Selection.open();
this.btnEditL2.setVisible(true);
}