Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some work I have found a neat way to communicate with the java runtime which doesn't trigger a refresh of the page every time there is communication. It is inspired on the way JSONP works to get around the cross domain restriction in most browsers these days. Because an iFrame will also trigger a <code>command://</code> url it possible to do a JSONP like action using this technique. The code on the client side (browser):</p> <pre><code> dojo.provide( "nmpo.io.java" ); dojo.require( "dojo.io.script" ); nmpo.io.java = dojo.delegate( dojo.io.script, { attach: function(/*String*/id, /*String*/url, /*Document?*/frameDocument){ // summary: // creates a new tag pointing to the specified URL and // adds it to the document. // description: // Attaches the script element to the DOM. Use this method if you // just want to attach a script to the DOM and do not care when or // if it loads. var frame = dojo.create( "iframe", { id: id, frameborder: 0, framespacing: 0 }, dojo.body( ) ); dojo.style( frame, { display: "none" } ); dojo.attr( frame, { src: url } ); return frame; }, _makeScriptDeferred: function(/*Object*/args){ //summary: // sets up a Deferred object for an IO request. var dfd = dojo._ioSetArgs(args, this._deferredCancel, this._deferredOk, this._deferredError); var ioArgs = dfd.ioArgs; ioArgs.id = dojo._scopeName + "IoScript" + (this._counter++); ioArgs.canDelete = false; //Special setup for jsonp case ioArgs.jsonp = args.callbackParamName || args.jsonp; if(ioArgs.jsonp){ //Add the jsonp parameter. ioArgs.query = ioArgs.query || ""; if(ioArgs.query.length > 0){ ioArgs.query += "&"; } ioArgs.query += ioArgs.jsonp + "=" + (args.frameDoc ? "parent." : "") + "nmpo.io.java.jsonp_" + ioArgs.id + "._jsonpCallback"; ioArgs.frameDoc = args.frameDoc; //Setup the Deferred to have the jsonp callback. ioArgs.canDelete = true; dfd._jsonpCallback = this._jsonpCallback; this["jsonp_" + ioArgs.id] = dfd; } return dfd; // dojo.Deferred } }); </code></pre> <p>When a request is sent to the java runtime a callback argument will be supplied and a <code>webBrowser.executeJavascript( callbackName + "(" + json + ");" );</code> action can be executed to trigger the callback in the browser.</p> <p>Usage example client:</p> <pre><code> dojo.require( "nmpo.io.java" ); nmpo.io.java.get({ // For some reason the first paramater (the one after the '?') is never in the // paramater array in the java runtime. As a work around we stick in a dummy. url: "command://sum?_", callbackParamName: "callback", content: { numbers: [ 1, 2, 3, 4, 5 ].join( "," ) }, load: function( result ){ console.log( "A result was returned, the sum was [ " + result.result + " ]" ); } }); </code></pre> <p>Usage example java:</p> <pre><code> webBrowser.addWebBrowserListener(new WebBrowserAdapter() { @Override public void commandReceived(WebBrowserCommandEvent e) { // Check if you have the right command here, left out for the example // Parse the paramaters into a Hashtable or something, also left out for the example int sum = 0; for( String number : arguments.get( "numbers" ).split( "," ) ){ sum += Integer.parseInt( number ); } // Execute the javascript callback like would happen with a regular JSONP call. webBrowser.executeJavascript( arguments.get( "callback" ) + "({ result: " + sum + " });" ); } }); </code></pre> <p>Also with IE in the frame I can highly recommend using firebug lite, the dev tools for IE are not available.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload