Search code examples
jquerygwtvaadingwtquery

How to add GWTQuery to an existing Vaadin Project?


I am new to Vaadin and GWT but i'm an advanced javascript Programmer. Now im working on a Vaadin existing Project and want to use the great possibilities of jQuery into my Project... how can i add GWTQuery into an existing Vaadin Project?


Solution

  • 1.- If you are using maven add these lines to your pom.xml:

    <dependency>
     <groupId>com.googlecode.gwtquery</groupId>
     <artifactId>gwtquery</artifactId>
     <version>1.2.0</version>
     <scope>provided</scope>
    </dependency>
    

    Otherwise download gwtquery-1.2.0.jar from the project site and include it in your classpath

    2.- Add this line to your_application.gwt.xml file:

    <inherits name='com.google.gwt.query.Query'/>
    

    3.- Import statically methods from the GQuery class

    import static com.google.gwt.query.client.GQuery.*;
    

    4.- Use it to enhance your dom or widgets

    $("css_selector").css("width", "100%");
    $("css_selector", my_widget).hide();
    

    5.- Be aware that you cannot use jquery plugins, but you can use the core api of jquery (with some differences). There are many gquery plugins though.