Call JSNI Java function from javascript via a frame in GWT - $wnd is undefined error
<p>I know I'm probably just doing something stupid but I cannot find an example that actually shows how to call a Java method from javascript using GWT.</p>

<p><a href="http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#calling" rel="nofollow">I've followed the documentation almost verbatim where is says:</a></p>

<pre><code>package mypackage;

public class Account {
private int balance = 0;
public int add(int amt) {
  balance += amt;
}

public native void exportAdd() /*-{
    var that = this;
    $wnd.add = $entry(function(amt) {
      that.@mypackage.Account::add(I)(amt);
    });
}-*/;
}
</code></pre>

<p>Then you can call it in JS using</p>

<pre><code>$wnd.add(5);
</code></pre>

<p>But that results in an error for me that says "$wnd is undefined".</p>

<p>This is my code:
I export the function call</p>

<pre><code>public native void exportPaymentProcessComplete()/*-{
    var that = this;
    console.log('exportingPaymentProcessComplete');
    $wnd.paymentProcessComplete = $entry(function(result){
        that.@com.ec.client.checkout.Presenter::paymentProcessComplete(Ljava/lang/String;)(result);
    });

}-*/;
</code></pre>

<p>I have a simple function that's being called (with a breakpoint because I've yet to get it to be called)</p>

<pre><code>public void paymentProcessComplete(String result){
    if(result != null){

    }
}
</code></pre>

<p>This is the tricky part and probably where I'm going wrong. The JSNI call is being made from an iframe when it loads. I think it has to do with trying to call the parent window's javascript functions but I'm not sure how to refer to the parents $wnd object. </p>

<p>I've tried this:</p>

<pre><code>response.getWriter().print("&lt;script type=\"text/javascript\"&gt;parent.$wnd.paymentProcessComplete(\"SUCCESS\");&lt;/script&gt;");
</code></pre>

<p>Which is when I get the "$wnd is undefined" error.</p>

<p>And also this:</p>

<pre><code>response.getWriter().print("&lt;script type=\"text/javascript\"&gt;parent.paymentProcessComplete(\"SUCCESS\");&lt;/script&gt;");
</code></pre>

<p>Which gives me a "Unable to get property 'paymentProcessComplete' of undefined or null reference". Which is basically the same error as "$wnd is undefined".</p>

<p>Anyone have any thoughts on how to accomplish this?</p>