当前位置: 首页>>代码示例>>Java>>正文


Java BootstrapListener类代码示例

本文整理汇总了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");
        }
    });
}
 
开发者ID:vaadin,项目名称:trippy,代码行数:47,代码来源:TrippyServiceInitListener.java


注:本文中的com.vaadin.server.BootstrapListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。