So you've got your web.gwt.xml
, your module, and your EntryPoint
all set up. If you don't have those things, this isn't the answer for you. The documentation isn't a bad place to start. This answer will use Opentip as an example, but I don't see why it wouldn't work for others too; specifically, though, this is geared for if you have widgets set up solely in GWT (not accessible from your HTML) and need to bind your external JS to them to enable some functionality.
Crack open your
web.gwt.xml
and make sure you're including your library's source in the entry for the module where you want to use it. This means that you don't have to declare it in your page's static HTML if you don't specifically need it there as well.<script src="../js/opentip/opentip-jquery.min.js"/>
(Note the
../
- this is a relative path from where your GWT-generated HTML file ends up on your server, and it has to be accessible by your web server.)In the module class where you want to use the library, rig up a JSNI method, calling your library constructor like so:
private native void initTooltip() /*-{ new $wnd.Opentip($doc.getElementById("tooltipTrigger"), "Tooltip text"); }-*/;
(Note the
$wnd
for referring to the top-level window and the$doc
for referring to the document. Prepending$wnd.
works for referring to any global variables declared/assigned in external JS files.)
No fancy Overlay types or ScriptInjector
calls needed. I did have one other problem while working this out - my call to getElementById()
was coming back null
- this turned out to be because I was calling my JSNI method before the relevant object had been added to the DOM during onModuleLoad()
.
Like I thought initially, this turned out to be a simple beginner's mistake; hope this can help someone else trying to piece together other answers to similar questions into a workable solution for their problem.