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 window object directly inside method. when accessing browser’s window , document objects jsni, must reference them $wnd , $doc, respectively. compiled script runs in nested frame, , $wnd , $doc automatically initialized correctly refer host page’s window , document.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -