0

In a RCP application I am displaying a GWT-based web-application in a SWT Browser.

My Goal is, to call a Java Method from within the GWT application.

From what I understand the easiest way to do that is to use SWT BrowserFunction, which injects a java Method that I can call from within the web-application.

For some reason I'm not able to get it to work...

In RCP I defined the following

public class GWTBrowserView extends ViewPart { 
    private GWTBrowser browser; 

    @Override 
    public void createPartControl(final Composite parent) { 
            this.browser = new GWTBrowser(parent, SWT.NONE); 
            this.browser.setUrl("url of gwt app"); 
            new BrowserFunction(this.browser, "onGWTEvent") { 

                    @Override 
                    public Object function(final Object[] arguments) { 
                            // Do something fancy
                            return super.function(arguments); 
                    } 
            }; 
    } 

In my GWT EntryPoint as part of onModuleLoad I am calling the Method:

private native void fireRCPEvent(String rcpEventJSON) /*-{
try{
    onGWTEvent(rcpEventJSON);
} catch(e) {
    alert(e.message)
}

Any ideas how to establish the communication between GWT and RCP via the SWT Browser?

1 Answer 1

2

You are calling wrong function from your JSNI. It should be:

private native void fireRCPEvent(String rcpEventJSON) /*-{
 try{
    $wnd.onGWTEvent(rcpEventJSON); //notice the usage of $wnd object
 } catch(e) {
    alert(e.message)
 }
}-*/

GWT compiled JS code is usually running in some separated context (iframe for example), so you have to explicitly specify that you want to call function from parent window ($wnd object), when you need to call external function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.