简体   繁体   中英

Vaadin dynamic loading JavaScript, CustomLayout

I have an application based on Vaadin 7, now I want to add my Components into CustomLayout the problem is that CustomLayout ignores - header part of template (static html) file so resources that described there ignored too. Static html files are not part of Vaadin application and they generated dynamically. How could I load JS and CSS files (that belongs to static html) on client side without annotations:

@JavaScript; @StyleSheet

and also approach with JavaScript.execute() also isn't good approach.

Why exactly these solutions are not good for you? Based on my experiences these work just fine. However, there is another solution: to just include an external javascript file into the page, extend the ApplicationServlet class, and override the writeAjaxPageHtmlVaadinScripts method.

`@Override
protected void writeAjaxPageHtmlVaadinScripts(Window window, String themeName, Application application, BufferedWriter page, String appUrl, String themeUri, String appId, ServletRequest request) throws ServletException, IOException {
  page.write("<script type=\"text/javascript\">\n");
  page.write("//<![CDATA[\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/jquery/jquery-1.4.4.min.js'><\\/script>\");\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/highcharts/highcharts.js'><\\/script>\");\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/highcharts/modules/exporting.js'><\\/script>\");\n");
  page.write("//]]>\n</script>\n");
  super.writeAjaxPageHtmlVaadinScripts(window, themeName, application,
      page, appUrl, themeUri, appId, request);
}

`

See this post for more details: How to add d3 (javascript) to a vaadin application?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM