Reputation: 19
We use GWT 2.3.0 for our web applications. We have started to use gwtquery for some of our features.
I would like to know if it is possible to call a jquery function within a js file from gwtquery.
Upvotes: 0
Views: 390
Reputation: 9741
gwtquery aka gQuery is a completely re-written implementation of the jquery for java.
One of the goal of gQuery is to have most of the features of jquery (css selectors, dom manipulation, effects, promises, ajax, etc) but without having to import the external jquery.js library, benefiting of all goodness of gwt (optimization, performance, dead code removal etc.).
In consequence, gQuery and jQuery cannot share plugins, so if you are using jquery.js in your app because you are using a jquery-plugin you still have to import jquery in your project.
In summary, if you wanted to use the syntax of the jquery but in gwt, you dont need to import jquery not call external js methods from java.
import static com.google.gwt.query.client.GQuery.*;
public void onModuleLoad() {
//add a click handler on the button
$("button").click(new Function(){
public void f() {
//display the text with effects and animate its background color
$("#text").as(Effects)
.clipDown()
.animate("backgroundColor: 'yellow'", 500)
.delay(1000)
.animate("backgroundColor: '#fff'", 1500);
}
});
}
Otherwise, if you don't use gquery and want to import jquery in your page, in order to call some methods from gwt, you must write jsni methods:
native void enhanceMyButton() /*-{
$("button").click(function() {
//display the text with effects and animate its background color
$("#text").as(Effects)
.clipDown()
.animate("backgroundColor: 'yellow'", 500)
.delay(1000)
.animate("backgroundColor: '#fff'", 1500);
});
}-*/;
Finally, in gwtquery, we are working on exposing gquery methods to integrate pure jquery code. This work is being done on a module we have called jsQuery, and the main goals are: that designers could add jquery code in html or ui.xml without importing the external jquery.js, and it can be a fast way to port a jquery plugin to gquery.
FYI: I posted here some of the benefits of using gquery as a complement of gwt
Upvotes: 0