简体   繁体   English

Vaadin动态加载JavaScript,CustomLayout

[英]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. 我有一个基于Vaadin 7的应用程序,现在我想将我的组件添加到CustomLayout中,问题是CustomLayout忽略了-模板(静态html)文件的标头部分,因此那里描述的资源也被忽略了。 Static html files are not part of Vaadin application and they generated dynamically. 静态html文件不是Vaadin应用程序的一部分,而是动态生成的。 How could I load JS and CSS files (that belongs to static html) on client side without annotations: 我如何在客户端上加载没有注释的JS和CSS文件(属于静态html):

@JavaScript; @StyleSheet

and also approach with JavaScript.execute() also isn't good approach. 并且使用JavaScript.execute()也不是一个好方法。

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. 但是,还有另一种解决方案:只在页面中包含一个外部javascript文件,扩展ApplicationServlet类,并重写writeAjaxPageHtmlVaadinScripts方法。

`@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? 有关更多详细信息,请参见此帖子: 如何将d3(javascript)添加到vaadin应用程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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