hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Cannot get LoadingIndicatorConfiguration from AppShellSettings

Open haijian-vaadin opened this issue 5 years ago • 2 comments

To reproduce:

  1. Extract the attached application.
  2. Put a break point in the AppShell's configurePage method
  3. Debug the application
  4. settings.getLoadingIndicatorConfiguration(); returns Optional.Empty

example.zip

haijian-vaadin avatar Mar 05 '20 21:03 haijian-vaadin

Did a quick debug, the reason is that getUi() returns null in AppSettings. So all the methods that rely on getUi() won't work.

haijian-vaadin avatar Mar 05 '20 22:03 haijian-vaadin

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:

  1. implement the VaadinServiceInitListener interface, and override the serviceInit() 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);
        });
      }
    }
    
  2. create a plain text file named com.vaadin.flow.server.VaadinServiceInitListener inside the src/main/resources/META-INF/services folder, and add there the full-qualified name of the class that implements the VaadinServiceInitListener interfance
    org.vaadin.example.AppShell
    

vlukashov avatar Mar 11 '20 21:03 vlukashov