Skip to content Skip to sidebar Skip to footer

How To Get Return Value To Eclipse Function From Java Script Function Which Get Data From Ajax Request Using SWT Browser?

I have tried below.... I have this in eclipse : I have a button in java which triggers this function in javascript Object status = browserCtrl.evaluate('return atm.java.webToJ

Solution 1:

When dealing with Ajax calls, you'll have to call a so-called BrowserFuntion from your Javascript code when you have the result.

Here's an example of how to define a BrowserFunction and how to call it from Javascript:

public static void main(String[] args)
{
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Browser browser = new Browser(shell, SWT.NONE);
    browser.setText("<a href='#' onClick='theJavaFunction()'>Click me!</a>");

    new BrowserFunction(browser, "theJavaFunction")
    {
        @Override
        public Object function(Object[] objects)
        {
            System.out.println("Call from Javascript");

            return null;
        }
    };

    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
}

Furthermore, an excellent tutorial about Browser from Vogella here:

http://blog.vogella.com/2009/12/21/javascript-swt/


Post a Comment for "How To Get Return Value To Eclipse Function From Java Script Function Which Get Data From Ajax Request Using SWT Browser?"