jsni

Does GWT JSNI support callbacks?

安稳与你 提交于 2019-12-05 10:07:23
问题 I am building a GWT app that uses Web SQL Local Storage ( http://dev.w3.org/html5/webdatabase/ ). The problem is that the Web SQL API uses callback functions as arguments. Is it possible to pass "Java" callbacks to JSNI? 回答1: Yes, it does: private static native void doThingWithCallback() /*-{ var self = this; var callbackFn = $entry(function(val) { self.@com.your.package.AClass.aMethod(Ljava/lang/String;)(val); }); $wnd.someApiThatTakesACallback(callbackFn); }-*/; Two things to remember:

GWT Synchronous call

强颜欢笑 提交于 2019-12-05 04:35:59
问题 I have a method in GWT which retrieves the DATA from the DB using the fire method of the requests as you all know its asynchronous I am calling this method from JS so I need to make synchronous is it possible private static String retriveLocation(String part) { ClientFactory clientFactory = GWT.create(ClientFactory.class); MyRequestFactory requestFactory = clientFactory.getRequestFactory(); YadgetRequest request = requestFactory.yadgetRequest(); String criteria = "!" + part; final ArrayList

JSNI GWT jquery

走远了吗. 提交于 2019-12-05 00:54:25
问题 I have a file jQuery to create the flip card effect and I changed it to JSNI, use native function but error. I don't know what's wrong. Can anybody help me? This is my native function: public native void flip() /*-{ $(document).ready(function () { $('#nav-list-example div div.back').hide().css('left', 0); function mySideChange(front) { if (front) { $(this).parent().find('div.front').show(); $(this).parent().find('div.back').hide(); } else { $(this).parent().find('div.front').hide(); $(this)

HTML5 and Javascript : Opening and Reading a Local File with File API

一曲冷凌霜 提交于 2019-12-04 19:43:10
I am using Google Web Toolkit for a project and would like the user to select a text file to open in a text window inside the browser. Here's the almost working code: private DialogBox createUploadBox() { final DialogBox uploadBox = new DialogBox(); VerticalPanel vpanel = new VerticalPanel(); String title = "Select a .gms file to open:"; final FileUpload upload = new FileUpload(); uploadBox.setText(title); uploadBox.setWidget(vpanel); HorizontalPanel buttons = new HorizontalPanel(); HorizontalPanel errorPane = new HorizontalPanel(); Button openButton = new Button( "Open", new ClickHandler() {

Synchronous RPC Calls in GWT

风格不统一 提交于 2019-12-04 03:06:05
(That title alone should cause people to come out of the woodwork to bash me with clubs, but hear me out). I have a use case where I need to return a value from a asynchronous call. (I'm using GWT-Platform, but the concepts are the same.) I declared a final JavaScriptObject array, then assigned the value within the AsyncCallback. However, I need to return the value, and the method returns before the AsyncCallback completes. Therefore, I need to block somehow until the AsyncCallback completes. I need the returned value in another method, or I'd just do what I need to in onSuccess(). I've tried

Does GWT JSNI support callbacks?

落花浮王杯 提交于 2019-12-03 22:36:31
I am building a GWT app that uses Web SQL Local Storage ( http://dev.w3.org/html5/webdatabase/ ). The problem is that the Web SQL API uses callback functions as arguments. Is it possible to pass "Java" callbacks to JSNI? Yes, it does: private static native void doThingWithCallback() /*-{ var self = this; var callbackFn = $entry(function(val) { self.@com.your.package.AClass.aMethod(Ljava/lang/String;)(val); }); $wnd.someApiThatTakesACallback(callbackFn); }-*/; Two things to remember: $entry() reminds GWT to keep track of the code when using the debugger. var self = this keeps the reference to

GWT Synchronous call

送分小仙女□ 提交于 2019-12-03 21:23:23
I have a method in GWT which retrieves the DATA from the DB using the fire method of the requests as you all know its asynchronous I am calling this method from JS so I need to make synchronous is it possible private static String retriveLocation(String part) { ClientFactory clientFactory = GWT.create(ClientFactory.class); MyRequestFactory requestFactory = clientFactory.getRequestFactory(); YadgetRequest request = requestFactory.yadgetRequest(); String criteria = "!" + part; final ArrayList<String> tags = new ArrayList<String>(); request.getTagsStartingWith(criteria, 10, 0).fire( new Receiver

JSNI GWT jquery

江枫思渺然 提交于 2019-12-03 16:17:05
I have a file jQuery to create the flip card effect and I changed it to JSNI, use native function but error. I don't know what's wrong. Can anybody help me? This is my native function: public native void flip() /*-{ $(document).ready(function () { $('#nav-list-example div div.back').hide().css('left', 0); function mySideChange(front) { if (front) { $(this).parent().find('div.front').show(); $(this).parent().find('div.back').hide(); } else { $(this).parent().find('div.front').hide(); $(this).parent().find('div.back').show(); } } $('#nav-list-example div').hover( function () { $(this).find('div'

GWT: Best practice for unit testing / mocking JSNI methods?

妖精的绣舞 提交于 2019-12-01 18:52:26
I have a class which uses JSNI to retrieve JSON data stored in the host page: protected native JsArray<JsonModel> getModels() /*-{ return $wnd.jsonData; }-*/; This method is called, and the data is then translated and process in a different method. How should I unit test this class, since I'm not able to instantiate (or seemingly mock?) JsArray? What is the best way to unit test JSNI methods at all? The interface approach is the best approach, and not necessarily an overkill. As to the problem of actually testing the method - well, if it is just reading from $wnd.jsonData, there isn't any

GWT JSNI javascript to Java not working

半腔热情 提交于 2019-12-01 11:14:48
I am trying to invoke a Java Method from my Javascript code. This is for a Windows Phone 7 app using Phonegap. I have the following in my javascript code. document.addEventListener("backbutton", onBackKeyDown, false); function onBackKeyDown(){ } And in my Java code I have the following. public static native void exportStaticMethod() /*-{ $wnd.onBackKeyDown = $entry(this.@com.mycompany.myapp.client.MyApp::hideSettingsWidgets()); }-*/; Then in the on onModuleLoad() I am calling it like so: MyApp.exportStaticMethod(); It does not work I have an alert in the hideSettingsWidgets() but it never gets