我需要根据用于访问应用程序的主机名设置 vaadin 应用程序的主题,例如app.company.de 使用“valo”,app.company.org 使用“org-theme”。
如果我在 UI 类中设置 UI 编程,则会出现“闪烁”,因为首先使用 @Theme
中的主题。
我还尝试通过添加 BootstrapListener
来修改引导页面,如下所示:
@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);
}
}
}
但这会导致一些转义问题,这些问题可能会解决,但我仍然不喜欢以如此古怪的方式更改 bootstrap js。
有没有办法连接到 bootstrap js 的创建位置?
最佳答案
使用自定义 UIProvider
重写 getTheme 方法怎么样?
public String getTheme(UICreateEvent event) {...}
另一个解决方案可以是扩展 VaadinServletService
并覆盖 getConfiguredTheme。
public String getConfiguredTheme(VaadinRequest request) {...}
关于java - 按主机名设置 vaadin 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39791402/