hilla
hilla copied to clipboard
Cannot get LoadingIndicatorConfiguration from AppShellSettings
To reproduce:
- Extract the attached application.
- Put a break point in the
AppShell'sconfigurePagemethod - Debug the application
settings.getLoadingIndicatorConfiguration();returnsOptional.Empty
Did a quick debug, the reason is that getUi() returns null in AppSettings. So all the methods that rely on getUi() won't work.
In Vaadin 15 the server-side UI instance is created separately, possibly after the app shell is initialized. However, the loading indicator config is tied to the UI instance. That's why the loading indicator config inside the AppShell's configurePage method is an empty Optional by default.
Meanwhile, it's still possible to configure the loading indicator in the way you want, but you'd need to use the VaadinServiceInitListener API for that.
That requires two steps:
- implement the
VaadinServiceInitListenerinterface, and override theserviceInit()event handler there:@CssImport("loading-indicator.css") public class AppShell implements AppShellConfigurator, VaadinServiceInitListener { @Override public void serviceInit(ServiceInitEvent serviceInitEvent) { serviceInitEvent.getSource().addUIInitListener(uiInitEvent -> { uiInitEvent.getUI().getLoadingIndicatorConfiguration() .setApplyDefaultTheme(false); }); } } - create a plain text file named
com.vaadin.flow.server.VaadinServiceInitListenerinside thesrc/main/resources/META-INF/servicesfolder, and add there the full-qualified name of the class that implements theVaadinServiceInitListenerinterfanceorg.vaadin.example.AppShell