是否可以在Vaadin框架内使用jQuery? [英] Is it possible to use jQuery inside of Vaadin framework?

查看:97
本文介绍了是否可以在Vaadin框架内使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Vaadin是一个Java Web应用程序框架,因此可以在Vaadin Java代码中插入jQuery javascript片段吗?

As Vaadin is a Java web application framework, so is it possible to insert the jQuery javascript snippet in the Vaadin Java code?

推荐答案

是的。

像这样创建你自己的ApplicationServlet扩展类:

Create your own ApplicationServlet extending class like this:

public class MyApplicationServlet extends ApplicationServlet {

    @Override
    protected void writeAjaxPageHtmlVaadinScripts(Window window,
            String themeName, Application application, BufferedWriter page,
            String appUrl, String themeUri, String appId,
            HttpServletRequest request) throws ServletException, IOException {

        page.write("<script type=\"text/javascript\">\n");
        page.write("//<![CDATA[\n");
        page.write("document.write(\"<script language='javascript' src='./jquery/jquery-1.4.4.min.js'><\\/script>\");\n");
        page.write("//]]>\n</script>\n");

        super.writeAjaxPageHtmlVaadinScripts(window, themeName, application,
            page, appUrl, themeUri, appId, request);
    }
}

然后替换web.xml中的Vaadin servlet(默认值为 com.vaadin.terminal.gwt.server.ApplicationServlet ):

Then replace the Vaadin servlet in your web.xml (the default is com.vaadin.terminal.gwt.server.ApplicationServlet):

<servlet-class>com.example.MyApplicationServlet</servlet-class>

然后,您可以通过调用以下代码在代码中进行jQuery调用:

You can then make jQuery calls in your code by calling:

MyApplication.getMainWindow().executeJavascript(jQueryString);

这篇关于是否可以在Vaadin框架内使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆