jsni

Javascript generic clone() method used in GWT application

妖精的绣舞 提交于 2019-12-09 17:56:08
问题 I was trying to write a generic clone function which should be able to do true deep cloning. I have come across this link, How to Deep clone in javascript and took the function from there. That code workds pretty well when I try using direct Javascript. I did minor modifications in the code and tried to put in the JSNI code in GWT. clone function: deepCopy = function(item) { if (!item) { return item; } // null, undefined values check var types = [ Number, String, Boolean ], result; //

GWT XMPP client using GWT-Strophe

可紊 提交于 2019-12-08 10:44:56
问题 I'm using GWT-Strophe to connect to my XMPP server. Things are going well and I am able to connect to my XMPP server and send other users messages. I'm having a problem with receiving messages. I'm attempting to copy the Strophe echobot example, but the code in my Handler is not getting executed when a message is received. Here is the code I am using to connect and register the handler: connection = new Connection("http://localhost/proxy/"); handler = new Handler<Element>() { @Override public

In GWT how to know all the styles applied to a given element (by id or class name)

情到浓时终转凉″ 提交于 2019-12-08 05:17:24
问题 I have the following problem : in my GWT project there is a "main" css file for the application, inline css in the DOM that come from the application computation and a css file that is bundled in an archive uploaded to the application and dynamically loaded. Now I need for an Element to find which CSS rules are applied, coming from either of the three sources. As I understand, GWT's getStyle() function only returns informations that are in the DOM. What's the simplest way to achieve this ?

Convert Base64 String with Gwt

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 13:49:31
问题 How to convert a base64 String to byte array with Gwt client side code? This link shows a encode decode, for base64 but not to byte[] array https://snipt.net/tweakt/gwt-base64/ 回答1: You have two options: 1- Use native JS methods btoa and atob, and convert the returned string to a java byte[] array: native String btoa(String b64) /*-{ return btoa(b64); }-*/; ... byte[] result = btoa(myBase64Data).getBytes(); 2- Use a pure java implementation of Base64 algorithm. You can just copy the

Adding a div element inside a panel?

我只是一个虾纸丫 提交于 2019-12-07 05:09:27
I'm working with GWT and I'm trying to add google-maps to my website. Since I want to use google-maps V3 I'm using JSNI. In order to display the map in my website I need to create a div element with id="map" and get it in the initialization function of the map. I did so, and it worked out fine but its location on the webpage is funny and I want it to be attached to a panel I'm creating in my code. So my question is how can I do it? Can I create a div somehow with GWT inside a panel ? I've tried to do create a new HTMLPanel like this: runsPanel.add(new HTMLPanel("<div id=\"map\"></div>"));

Convert Base64 String with Gwt

怎甘沉沦 提交于 2019-12-06 02:41:06
How to convert a base64 String to byte array with Gwt client side code? This link shows a encode decode, for base64 but not to byte[] array https://snipt.net/tweakt/gwt-base64/ You have two options: 1- Use native JS methods btoa and atob , and convert the returned string to a java byte[] array: native String btoa(String b64) /*-{ return btoa(b64); }-*/; ... byte[] result = btoa(myBase64Data).getBytes(); 2- Use a pure java implementation of Base64 algorithm. You can just copy the Base64Utils.java included in the gwt-user.jar, and copy it to your client package, and use its methods: import my

GWT - Calling instance method from external javascript

让人想犯罪 __ 提交于 2019-12-06 00:47:52
问题 There is this $entry method that we can use in GWT to allow external javascript to execute java methods. You can see the explanations in their documentation https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI?hl=fr#calling However, the example there is only with static methods. I'm trying to write it for a non-static method and when I try to call it, I get an exception : java.lang.ClassCastException: Cannot cast com.google.gwt.core.client.JavaScriptObject$ to

How to pass javascript object to GWT method and parse result

被刻印的时光 ゝ 提交于 2019-12-05 22:30:47
I have this GWT method: public static native JavaScriptObject getJsValue() /*-{ var res = $wnd.product; return res; }-*/; This is the HTML/JS part: <script type="text/javascript" language="javascript"> var product = products({id:1}).first(); </script> <!-- GWT --> <script type="text/javascript" language="javascript" src="app/app.nocache.js"></script> The object product looks like this in Firebug: Object { id=1, categoryid=0, name="Sample Product", more...} After then, Object obj = getJsValue(); // what cast? However, how can I parse the resulting value to get the field values like the product

Synchronous RPC Calls in GWT

独自空忆成欢 提交于 2019-12-05 19:49:02
问题 (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.

GWT 2.x $entry function

两盒软妹~` 提交于 2019-12-05 18:31:04
问题 Cannot find any developer information about this function. I just know that it's suggested to wrap JSNI JavaScript calls to Java methods with this $entry function. I found that it catches exceptions so Java code could handle them. Is it all it does? 回答1: If you want to know exactly what happens, look into com.google.gwt.core.client.impl.Impl.entry(JavaScriptObject jsFunction) . This function (at least in GWT 2.2.0) mainly calls entry0(Object jsFunction, Object thisObj, Object arguments) ,