jsni

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

时光怂恿深爱的人放手 提交于 2019-12-19 21:52:37
问题 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? 回答1: The interface approach is the best approach, and not necessarily an overkill. As to the

Calling GWT Java function from JavaScript

巧了我就是萌 提交于 2019-12-17 07:31:07
问题 I am a newcomer to GWT and JavaScript. There are similar question of this type I have tried to follow, but I keep failing. I have a GWT app, I need to call a Java function from Javascript( on the onclick of a href tag, in particular.) Following is what I have done. public class JSNITest { public static void handleAnchorClick(int a , int b) { Window.alert("Current row and Column is " + a + " " + b); } public static native void exportMyFunction()/*-{ $wnd.handleAnchorClick = function(param1

Calling GWT Java function from JavaScript

僤鯓⒐⒋嵵緔 提交于 2019-12-17 07:31:04
问题 I am a newcomer to GWT and JavaScript. There are similar question of this type I have tried to follow, but I keep failing. I have a GWT app, I need to call a Java function from Javascript( on the onclick of a href tag, in particular.) Following is what I have done. public class JSNITest { public static void handleAnchorClick(int a , int b) { Window.alert("Current row and Column is " + a + " " + b); } public static native void exportMyFunction()/*-{ $wnd.handleAnchorClick = function(param1

Creating New Array with Class Object in GWT

浪尽此生 提交于 2019-12-13 13:23:44
问题 I would like to create a new array with a given type from a class object in GWT. What I mean is I would like to emulate the functionality of java.lang.reflect.Array.newInstance(Class<?> componentClass, int size) The reason I need this to occur is that I have a library which occasionally needs to do the following: Class<?> cls = array.getClass(); Class<?> cmp = cls.getComponentType(); This works if I pass it an array class normally, but I can't dynamically create a new array from some

Use jquery inside GWT jsni

孤街浪徒 提交于 2019-12-13 11:33:24
问题 I am not able to use $("#"+profileId).offset().top from inside my gwt jsni function. I tried this $wnd.$("#"+profileId).offset().top but this is also not working. I feel i am missing syntax here. Could anybody help 回答1: Three solutions for this question: 1- Your Jsni code looks fine except that you have to enclose it in the corresponding native function and return a double (or any other number type if you want gwt to make the casting). native double getTop(String profileId) /*-{ return $wnd.$

What's the best way to have a GWT Presenter with a javaScript view?

 ̄綄美尐妖づ 提交于 2019-12-13 07:17:21
问题 I'm using GWT but 1 of my Ui programmers only knows javaScript but is learning Java right now. So what is the best way to have a javaScript view. I tried to use GWT exporter but I had this problem with it. I've heard that using GWT as glue code and doing the Ui in javaScript is common but I don't see any examples. I'd like to know the best practices for this. 来源: https://stackoverflow.com/questions/28139757/whats-the-best-way-to-have-a-gwt-presenter-with-a-javascript-view

how to instantiate a java class from within JSNI

佐手、 提交于 2019-12-13 07:06:43
问题 I'm trying to instantiate a java type inside a JSNI method body, using the JSO's package-private's ::new() method, but all instances are returned as null handles. how come? Is it possible to instantiate the class using a similar syntax to Java? Here is the relevant code: public class OnChangeHandlerJso extends JavaScriptObject { protected OnChangeHandlerJso() {}; public static native JavaScriptObject create() /*-{ return function(cm, changeInfo) { var eventBus = @com.gigaspaces.codemirror_gwt

Call Java from Javascript JSNI

柔情痞子 提交于 2019-12-13 06:09:05
问题 I am using SmartGWT and I wish to access com.smartgwt.client.Version from JavaScript. In Firefox's Web Console, I have tried: frames[0].$entry(Lcom_smartgwt_client_Version::getVersion())); and frames[0].$entry(@com.smartgwt.client.Version.getVersion()); and frames[0].$entry(@com.smartgwt.client.Version::getVersion()); and frames[0].$entry(@com.smartgwt.client.Version::getVersion()()); But all of them return a syntax error. SmartGWT is deployed with my WAR and I can see other SmartGWT classes

How to pass a GWT method as a parameter into a Javascript function?

这一生的挚爱 提交于 2019-12-13 04:02:01
问题 Overview There is a GWT method called: private void handleError() There is a JSNI Javascript function called: private native void registerErrorHandler() The native javascript function calls another function from a third party Javascript library: foo.attachEvent("EventName", handlerReference); Functionality I need to pass the GWT method as a function parameter into the foo.attachEvent() function, i tried several approaches: foo.attachEvent("Error", registerErrorHandler); ->

Passing javascript parameter from external javascript to java

℡╲_俬逩灬. 提交于 2019-12-12 22:04:28
问题 An external javascript gives a number that should be handed over to Java method named mycallback . I have defined: Java: class MyClass { public static void mycallback(JavaScriptObject number) { // do something with the number } } Javascript: $wnd.callback = $entry(@com.package.MyClass::mycallback(Lcom/google/gwt/core/client/JavaScriptObject)); And the Javascript call is: $wnd.callback(number_from_external_javascript); But I get error: JS value of type number, expected com.google.gwt.core