Invoke external function from jsni in GWT -
i have function defined in .js file, included in main .html file code:
<script type="text/javascript" language="javascript" src="js/script.js"></script> i have jsni method invokes function defined in js file:
public native void addjsmodule(string name) /*-{ addnewsection(name); }-*/; when invoke java method, exception:
com.google.gwt.event.shared.umbrellaexception: exception caught: exception caught: (referenceerror) @client.registros.home.registyhome::addjsmodule(ljava/lang/string;)([string: 'acercade']): addnewsection not defined thanks!!
gwt code runs (by default) in hidden iframe, script not available. there's $wnd variable referencing window object of enclosing browsing context (where script has been loaded). therefore have prefix function $wnd reference function defined in outer browsing context:
public native void addjsmodule(string name) /*-{ $wnd.addnewsection(name); }-*/; see http://www.gwtproject.org/doc/latest/devguidecodingbasicsjsni.html#writing
note code did not reference javascript
windowobject directly inside method. when accessing browser’s window , document objects jsni, must reference them$wnd,$doc, respectively. compiled script runs in nested frame, ,$wnd,$docautomatically initialized correctly refer host page’s window , document.
Comments
Post a Comment