Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use jQuery inside of Vaadin framework?

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

like image 870
Kyleinincubator Avatar asked Feb 15 '12 23:02

Kyleinincubator


People also ask

Does vaadin use jQuery?

Vaadin 14 manages frontend dependencies using npm and webpack. Vaadin 10-13 uses Bower and Webjars for this. The difference between this and the CDN option is that jQuery is bundled with the other frontend resources of the application, like Vaadin components. This is a good option if you don't want to rely on a CDN.

Is vaadin a JavaScript framework?

React and Vaadin are primarily classified as "Javascript UI Libraries" and "Frameworks (Full Stack)" tools respectively.

Is Vaadin framework good?

Vaadin is a mature web framework for developing rich internet applications. Building web-based GUIs with Vaadin feels like developing a desktop application, which is great, comfortable and fast. However, there are situations where Vaadin is not suitable.

Is vaadin widely used?

Vaadin, one of the most popular Java web development frameworks is widely used for building enterprise-grade and scalable web applications.


1 Answers

Yes it is.

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);
    }
}

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>

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

MyApplication.getMainWindow().executeJavascript(jQueryString);
like image 68
miq Avatar answered Sep 30 '22 02:09

miq