Set themes on early stage

Hi, I am trying to set the theme in my app using a JNDI parameter, so I can’t use the @Theme annotation.
I have tried to use the setTheme method the first thing in the init method of the UI but that’s already too late, since first you can see for a second the page without a theme, and after that second it loads the theme.

I have thought then to override the getTheme method in a custom CDIUIProvider, but it is ignoring it. This is my UI:

[code]
@Title(“My web”)
@CDIUI(“hello”)
@Push(transport= Transport.LONG_POLLING)
@PreserveOnRefresh
public final class MyUI extends UI
{
@WebServlet(value = “/hello”, asyncSupported = true, initParams =
{ @WebInitParam(name = Constants.SERVLET_PARAMETER_UI_PROVIDER, value = “com.whatever.CustomCDIUIProvider”) })
@VaadinServletConfiguration(productionMode = false, ui = MyUI.class)
public static class Servlet extends VaadinCDIServlet
{
}

..

[/code]This is CustomCDIUIProvider:

public class CustomCDIUIProvider extends CDIUIProvider { @Override public String getTheme (UICreateEvent event) { return "mytheme"; } } How do I configure it properly so it uses my overitten method? Is this the correct approach?

There is earlier thread about this topic here, check if the solution works for you also:

https://vaadin.com/forum#!/thread/12243078

Thank you, I had seen the second post but not the first.
If I do this it works! (I also added a custom heartbeat interval but that’s irrelevant)

[code]
@Title(“My web”)
@CDIUI(“hello”)
@Push(transport= Transport.LONG_POLLING)
@PreserveOnRefresh
public final class MyUI extends UI
{
@WebServlet(value = “/hello”, asyncSupported = true, initParams =
{ @WebInitParam(name = Constants.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, value = “90”) })
@VaadinServletConfiguration(productionMode = false, ui = MyUI.class)
public static class Servlet extends VaadinCDIServlet
{
@Override
protected void servletInitialized() throws ServletException
{
super.servletInitialized();

     getService().addSessionInitListener(e -> {

        e.getSession().addUIProvider(new CDIUIProvider() {

           @Override
           public String getTheme(UICreateEvent event) {
              return "mytheme";
           }
        });
     });
  }

}

[/code]But why can’t I set it in a class apart? I don’t like all this code in my UI class. Can somebody tell me why what I was doing before didn’t work?