Hi!
There are two ways to solve your problem.
First way
You can create a spring bean and put some callback in it as a field that will accept new parameters for your ComboBox component.
For example:
@Component("myapp_ComboBoxBinder")
public class ComboBoxBinder {
private Consumer<List<String>> parametersConsumer;
public void setParameters(Consumer<List<String>> parametersConsumer) {
this.parametersConsumer = parametersConsumer;
}
public void updateParameters(List<String> parameters) {
if (parametersConsumer != null) {
parametersConsumer.accept(parameters);
}
}
}
Next, you need to set this callback in your MainView:
@Autowired
private ComboBoxBinder comboBoxBinder;
@ViewComponent
private ComboBox<String> myComboBox;
@Subscribe
public void onInit(InitEvent event) {
comboBoxBinder.setParametersConsumer(this::setComboBoxValues);
}
public void setComboBoxValues(List<String> values) {
myComboBox.setItems(values);
}
And then, just use the installation of a new value through the binder where you need it:
@Autowired
private ComboBoxBinder comboBoxBinder;
public void someMethod() {
comboBoxBinder.updateParameters(newListOfParmaeters);
}
Second way
This way will be more correct.
You need to create an event to signal the update of data in the ComboBox. In the place that you need, you need to publish an event with a set of parameters for setting.
In the MainView, create a listener for the event that will update the data in the comboBox.
Here’s an article where you can learn more about creating an application events: https://www.baeldung.com/spring-events
Best regards,
Dmitriy