开发者

How to add a javascript script for use in GWT?

开发者 https://www.devze.com 2023-02-08 00:07 出处:网络
How do I add a script such as the jQuery library 开发者_StackOverflowso 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

How do I add a script such as the jQuery library 开发者_StackOverflowso 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.


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");
}-*/;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消