I have an app where i get the values to display in a combo box from the database when the application starts up. There is a REST endpoint that allows you to add additional values to the database. Now i want the app the reflect the newly added values in the combo box.
It sounds like i need to do something with the UI object since I need to update something that needs reflected on the UI outside of the UI thread, but i’m a little unclear on how to do that.
Right now I have my UI component implementing an interface that has an update() method, and the component registers itself as a listener. When the REST call is made and a new value added, i loop through the listeners calling the update() method
UI.getCurrent().access(() -> {
listeners.stream().forEach(listener -> listener.update());
});
but i get the following error:
java.lang.NullPointerException: Cannot invoke “com.vaadin.flow.component.UI.access(com.vaadin.flow.server.Command)” because the return value of “com.vaadin.flow.component.UI.getCurrent()” is null
so i am sure I am missing some basic priniciple on how to do this. Any help would be appreciated. Thank you!