Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3317386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:34:53+00:00 2026-05-17T22:34:53+00:00

Using DJ Native Swing it is possible to show a web page within a

  • 0

Using DJ Native Swing it is possible to show a web page within a java application. When you do this it is also possible to communicate from the browser to the java runtime environment using the “command” protocol. The documentation has a code snippet which demonstrates it’s usage:


function sendCommand( command ){
    var s = 'command://' + encodeURIComponent( command );

    for( var i = 1; i < arguments.length; s+= '&' + encodeURIComponent( arguments[i++] ) );
      window.location = s;
}

As it looks here it seems to be a regular GET request to an url using the command protocol instead of http. Although when I create and image, script tag or just and ajax get request there is no response and the breakpoint in the java runtime isn’t triggered.

I don’t want to set the window.location because I don’t want to navigate away from the page I am currently at. Using the link to navigate to a command url does work though but it also navigates away from the current page. The page uses OpenLayers and dojo. (I have also tried dojo.io.script)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:34:54+00:00Added an answer on May 17, 2026 at 10:34 pm

    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 command:// url it possible to do a JSONP like action using this technique. The code on the client side (browser):

    
    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
        }
    });
    

    When a request is sent to the java runtime a callback argument will be supplied and a webBrowser.executeJavascript( callbackName + "(" + json + ");" ); action can be executed to trigger the callback in the browser.

    Usage example client:

    
    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 + " ]" );  
        }   
    });
    

    Usage example java:

    
    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 + " });" );
        }
    });
    

    Also with IE in the frame I can highly recommend using firebug lite, the dev tools for IE are not available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application in java swing and I am using the following
I'm using the BrowserLauncher2 library for opening the user's default web browser from my
I'm using a native DLL (FastImage.dll) in a C# ASP.NET Web Service that sometimes
My application (C++ using SQL Native Client with SQL Server 2000) is consistently finding
I am using ngen.exe (the .Net Native Image Generator) version 2.0.50727.312. Is this the
We're using our .NET Assembly DLL within native C++ through COM (CCW). Whenever I
I am using Visual Studio, developing a native application, I have a programmatical breakpoint
Right now I'm using JNA for Java-native communication and am pleased with its simplicity.
Does anyone know any good tutorial about using NAnt for native code build process
I am trying to use native windows API with Qt using mingw toolset. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.