Xavier
Xavier

Reputation: 9049

How to add a javascript script for use in GWT?

How do I add a script such as the jQuery library so it is available for use in GWT? I know how to do JSNI, I just don't know how to make the jQuery library available to me so I can call it within JSNI.

Upvotes: 2

Views: 3342

Answers (2)

Xorty
Xorty

Reputation: 18851

They don't play well together, yet. The only way I know so far (correct me if I'm mistaken) is GWTQuery. Give it a try ;)

EDIT

I re-explained my thoughts, hope it'll be more clear now

It is possible to call any desired custom JavaScript code, see Jason's answer.

I recommend using GWTQuery, since it's successfull port of JQuery to Java-based GWT ecosystem and doesn't force you to use raw native JavaScript from Java code.

Upvotes: 2

Jason Hall
Jason Hall

Reputation: 20920

GWT can call any JS function or reference any JS variable on the page using JSNI, so as long as the JQuery script is also loaded on the page, you can call any JQuery code you want.

For example:

public native void callJQuery() /*-{
  $("p.neat").addClass("ohmy").show("slow");
}-*/;

Upvotes: 3

Related Questions