3 dependent Combox'es

Hi all,
I uses Vaadin 14 and I have problem with correct refreshing items in dependent ComboBox’es. I have one main ComboBox (comboProfile) and 2(comboEnvironment and comboScenario) which have pool of items dependent from selected value in first boxes.

comboProfile.addValueChangeListener((HasValue.ValueChangeEvent<String> event) -> {
      String value = event.getValue();
      switch (value) {
        case "1":
          comboEnviroment.setItems("11", "12");
          break;
        case "2":
          comboEnviroment.setItems("21");
          break;
        case "3":
          comboEnviroment.setItems("31", "32", "33");
          break;
        case "4":
          comboEnviroment.setItems("34");
          break;
      }
      comboScenario.setItems(scenarioList.stream().filter(c -> c.getProfile().equals(value)).map(Scenario::getName));

    });

Items are always correct refresh in combobox,where operation in done first (in this case comboEnvirnment), but for combobox where it is done next these items have been never refreshed ( in this case comboscenario). Only when I try to set them for the first time everything is correct. When I try to modificade them again by change value for main ComboBox( when all comboboxes has some values). I have error like that for last ComboBoxes(comboScenario)

2021-02-23 16:15:24.567 ERROR 5272 --- [nio-8080-exec-6]
 c.v.flow.server.DefaultErrorHandler      : 

java.util.NoSuchElementException: No value present
	at java.util.Optional.get(Optional.java:135) ~[na:1.8.0_201]

	at com.comarch.telco.t3arts.datagenerator.VaadinGUI.onScenarioCombobox(VaadinGUI.java:184) ~[classes/:na]

	at com.comarch.telco.t3arts.datagenerator.VaadinGUI.lambda$addValuesChangesListeners$3fab9f70$3(VaadinGUI.java:129) ~[classes/:na]

	at com.vaadin.flow.component.internal.AbstractFieldSupport.lambda$addValueChangeListener$828eca10$1(AbstractFieldSupport.java:96) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.Component.fireEvent(Component.java:359) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.ComponentUtil.fireEvent(ComponentUtil.java:386) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.internal.AbstractFieldSupport.setValue(AbstractFieldSupport.java:207) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.internal.AbstractFieldSupport.setValue(AbstractFieldSupport.java:133) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.AbstractField.setValue(AbstractField.java:181) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.combobox.ComboBox.setValue(ComboBox.java:345) ~[vaadin-combo-box-flow-3.2.2.jar:na]

	at com.vaadin.flow.component.HasValue.clear(HasValue.java:179) ~[flow-server-2.4.0.jar:2.4.0]

	at com.comarch.telco.t3arts.datagenerator.VaadinGUI.onRandomizeButtonAction(VaadinGUI.java:354) ~[classes/:na]

	at com.comarch.telco.t3arts.datagenerator.VaadinGUI.lambda$addValuesChangesListeners$9b1b5227$2(VaadinGUI.java:142) ~[classes/:na]

	at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) ~[flow-server-2.4.0.jar:2.4.0]

	at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373) ~[flow-server-2.4.0.jar:2.4.0]

	.
	.
	

I just tried to clear this combobox and set its value to null before setting new items but always this is the same effects and items which was set once can’t be refresh.
I’m new with this framework and will be grateful for help because don’t have idea where I made mistake

Does it only happen when there are no matching scenarios in the list, or always?

Does comboScenario have a value change listener as well? This will get triggered if you call comboScenario.clear(). look there for any possible Null pointer exceptions. The stack trace should point you to line 184 of your VaadinGUI class

Another thing I noticed is that your ComboBoxes seem to be of type <String>. I usually type them to the actual Object/Entity/Enum, for example ComboBox<Scenario> and define the items label like this: comboScenario.setItemLabelProvider(Scenario::getName). Maybe if other things don’t work you could try this out. This would also affect the line where you would now call comboScenario.setItems without the mapping of the filtered stream:

comboScenario.setItems(scenarioList.stream().filter(c -> c.getProfile().equals(value)).collect(Collectors.toList());

I just tried your advices but their didn’t help ;/
It always happens when comboScenario has some value. I can’t modificate items or clear it then because this error appeared.
Yes, my comboScenario has a value change listener. It does this action

    scenario = scenarioList.stream().filter(c -> c.getName().equals(value)).findFirst().get();

I think that maybe I would be reason of error because when I commented it there was no error anymore.
However It is strange that when comboScenario hasn’t items after build application, items are set without any error