Will work with no problem, I have done for my internal use a lot of wrappers to native JS so there is no
diff, JAVA here gets just compiled to js.
If you stay in the same window(no new tab or so) this will work,
you can name the methods what ever you like,
this will also work:
module A
public static native void setModuleAMessage(JavaScriptObject message) /*-{
$wnd.myMessage = message ;
}-*/;
public static native JavaScriptObject getModuleAMessage() /*-{
return $wnd.myMessage;
}-*/;
module B
public static native void setModuleBMessage(JavaScriptObject message) /*-{
$wnd.myMessage = message ;
}-*/;
public static native JavaScriptObject getModuleBMessage() /*-{
return $wnd.myMessage;
}-*/;
The methods dosent have to be static, you can make them private and seen just by the scooping object, what is important is that what ever
you do you have to use same JS variable name exp 'myMessage' this is a JS object with a 'public' scoping because its assigned to the window object ($wnd)
if You need to use the message in a new opened window or tab(sub children of the first) you can always in the module loaded in the child window create a method like this
public static native JavaScriptObject getMessageFromOpener() /*-{
return $wnd.opener.myMessage;
}-*/;
Also important if you try to access the object before its set ofcourse you will get undifined back. If you dont like this
you can 'init' the message on the very first load of the first module with a method like this
public static native void initMessage() /*-{
$wnd.myMessage = {};
}-*/;
Hope this helps.
Blaze
Am Montag, 28. Januar 2013 16:37:57 UTC+1 schrieb Clement:
Hi,--
Hi Blaze,
Can I use your idea in the below situation
I have a Search component which renders the search box.
This Search component is used by module A and also by module B.
Can I use the setter and getter method of native javascript in the search box component and invoke it in the same component when it is required.
Will this way of using Javascript Native object work,
Please share me your thoughts..
Also please provide me a sample of creating JavaScriptObject.
Thanks
Clement Amarnath
On Monday, January 28, 2013 7:51:57 PM UTC+5:30, Blaze wrote:Hi,
just like Thomas said, u can use any of this ways dipending on the req.
I had a req. where the two modules run in the same window and I used a JSNI methods
module A
public static native void setMessage(JavaScriptObject message) /*-{
$wnd.myMessage = message ;
}-*/;
public static native JavaScriptObject getMessage() /*-{
return $wnd.myMessage;
}-*/;
module B
public static native void setMessage(JavaScriptObject message) /*-{
$wnd.myMessage = message ;
}-*/;
public static native JavaScriptObject getMessage() /*-{
return $wnd.myMessage;
}-*/;
Hope this helps
B
Am Montag, 28. Januar 2013 14:47:12 UTC+1 schrieb Clement:Hi All,
I have the below requirement.
Currently we have two modules a.gwt.xml and b.gwt.xml and I have a scenario where the text entered in module A to be passed to module B.
I don't want to prefer the Cookie and Server side Session options.
Please share your ideas on how to pass messages between the modules.
Thanks in Advance
Clement Amarnath
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment