PDA

View Full Version : JSNI and Frame help



VadimV1144
10 Jan 2010, 2:25 AM
Hi I am a new to JSNI and can't seem to do do the following.

I have a gwt Frame that is sitting inside the GXT app (parent). Inside the frame another GXT app (child) is loaded.
I want to notify the parent app that some event has occurred on the child app (inside a frame) by calling a method on the parent GXT app instance.

How do I access the parent GXT instance form within the frame?
How do I invoke a method on parent instance?


Thanks

VadimV1144
11 Jan 2010, 12:03 AM
Here is what I am doing:
The main page is a simple HTTP. In the GWT widget that sits in the main window I define two methods. The registerNativeFunction() is called in the constructor so the variable cmc is initialized.


private native void registerNativeFunction(GeneralTestCases cmcThis) /*-{
top.cmc = "loaded from the top";
}-*/;

static public void getMessage(String url){
MessageBox.alert("test", url, null);
}


Within the parent GXT component an HTTPS page with its own GXT widget is loaded within a frame.
Inside the frame a GXT component calls the native method that should access the top level "cmc" variable:


public native void resetParentToPage(String url) /*-{
@com.krinka.examples.testclasses.GeneralTestCases::getMessage(Ljava/lang/String;)($wnd.top.cmc);
}-*/;


However, the top.cmc and even the top are undefined.
I tried different combinations of the DHTML components: top, window.top, $wnd.top, parent, window.parent, $wnd.parent .
None of them seem to work. From what I understand, top is topmost component and I should be able to access it from any div frame or other components that are on a page.
What am I doing incorrectly?

Arno.Nyhm
13 Jan 2010, 9:49 AM
but its different with iframe etc. then you have to call something other ...

also be aware that you can not access it when it comes from different domains.

my suggestion at first try to find out how this in plain html and plain javascript and if this works in GXT/GWT.

VadimV1144
13 Jan 2010, 9:55 AM
Thanks Arno, it turns out that it was the different domain issue (SOP). The iframe is sending/receiving data via an https and as a result it can't access the top page.