dve
dve

Reputation: 371

Set vaadin theme by hostname

I need to set the theme of a vaadin app depending on the hostname which is used to access the app e.g. app.company.de uses "valo", app.company.org uses "org-theme". If I set the UI programmatic in the UI class, I get a "flicker" because the theme from @Theme is used first. I also tried to modify the bootstrap page by adding a BootstrapListener like this:

            @Override
            public void modifyBootstrapPage(BootstrapPageResponse response) {
                Document doc = response.getDocument();
                for (Element script : doc.getElementsByTag("script")) {
                    if (script.html().contains("\"theme\": \"valo\"")) {
                        String old = script.html();
                        String newHtml = old.replace("valo", THEME_NAME);
                        script.html(newHtml);
                    }
                }
            }

But this leads to some escaping problems, which one might solve, but still I don't feel good by changing the bootstrap js a such a hacky way.

Is there a way to hook into where the bootstrap js is created?

Upvotes: 1

Views: 178

Answers (1)

Marco C
Marco C

Reputation: 981

What about using a custom UIProvider that overrides getTheme method?

public String getTheme(UICreateEvent event) {...}

Another solution could be extendinf VaadinServletService and override getConfiguredTheme.

public String getConfiguredTheme(VaadinRequest request) {...}

Upvotes: 1

Related Questions