How to I expose a Java class's functionality via some JavaScript interface in GWT? -
say have java class course has method testmethod. how expose functionality such can interact using hand-written javascript follows:
somecourse.testmethod(); where somecourse passed directly java code via native method, like:
private native void associatecourse(course course) /*-{ somecourse = course; }-*/; the main issue having in achieving gwt not provide way me access prototype of course constructor. example, following invalid:
private native void expose() /*-{ $wnd.course = @mypackage.course; }-*/; because expects access field, not whole thing.
i avoid using library gwt exporter because feel having incorporate source code handles application logic make difficult separate 2 aspects of code, bad thing if code shared between gwt project , android application, example.
if use gwt 2.7+ can use new jsinterop. hidden behind compiler flag, works quite well.
it still experimental , may change in future releases.
take @ demo: https://www.youtube.com/watch?v=wfmd1gxr2tg
Comments
Post a Comment