本文整理汇总了Java中com.vaadin.server.BootstrapListener类的典型用法代码示例。如果您正苦于以下问题:Java BootstrapListener类的具体用法?Java BootstrapListener怎么用?Java BootstrapListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BootstrapListener类属于com.vaadin.server包,在下文中一共展示了BootstrapListener类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serviceInit
import com.vaadin.server.BootstrapListener; //导入依赖的package包/类
@Override
public void serviceInit(ServiceInitEvent event) {
ValoDependencyFilter dependencyFilter = new ValoDependencyFilter();
if (dependencyFilter.hasValoWebJar()) {
event.addDependencyFilter(dependencyFilter);
}
VaadinServletService service = (VaadinServletService) event.getSource();
WebApplicationContext applicationContext = WebApplicationContextUtils
.findWebApplicationContext(
service.getServlet().getServletContext());
String apiKey = applicationContext.getEnvironment()
.getProperty("map.apikey");
if (apiKey == null) {
throw new RuntimeException(
"Configure a map.apikey in your application.properties");
}
event.addBootstrapListener(new BootstrapListener() {
@Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
Element head = response.getDocument().head();
head.appendElement("meta").attr("name", "viewport")
.attr("content", "width=device-width, initial-scale=1");
// Flow sets element properties too late for google-map to get
// the right API key. As a temporary workaround, we put our key
// in the map's prototype instead.
head.appendElement("script").html("window.mapApiKey = '"
+ apiKey + "';\n"
+ "customElements.whenDefined('google-map').then(function() {customElements.get('google-map').prototype.apiKey = window.mapApiKey})");
head.appendElement("link").attr("rel", "import").attr("href",
response.getUriResolver().resolveVaadinUri(
"frontend://bower_components/vaadin-valo-theme/typography.html"));
head.appendElement("link").attr("rel", "import").attr("href",
response.getUriResolver().resolveVaadinUri(
"frontend://bower_components/vaadin-valo-theme/color.html"));
head.appendElement("custom-style").appendElement("style")
.attr("include", "valo-typography valo-colors");
}
});
}