Help !!! How to open a new window

666 views
Skip to first unread message

Vikas Thakur

unread,
Jun 23, 2006, 10:48:12 AM6/23/06
to Google Web Toolkit
Hi,
I am developing an application which has many hyper links on the main
page and it needs to open new windows when someone clicks on those
hyperlinks, but the data in the new windows does not come from the
server but is already present on the client side. Can anyone tell me
how to accomplish that.
Right now I am using 'HyperLink' and Window.open in its action
listener, which does open a new window but I do not have access to its
content pane/panel so tht I can add my widgets
to it.
Thanks in anticipation

j...@google.com

unread,
Jun 28, 2006, 5:46:40 PM6/28/06
to Google Web Toolkit
The Window.open() method does not currently return a handle to the
opened window, because there's not a lot you can do with it from Java
(without resorting to JSNI methods). GWT cannot allow you to pass
objects easily back and forth, because the methods and properties on
those objects are compressed and unpredictable (i.e. Foo.bar() in Java
is probably called something like x.y() in Javascript). There are also
other optimizations that the compiler performs that would make this
problematic.

If you don't mind writing some Javascript, however, you could implement
what amounts to IPC between the two windows running separate GWT apps.
First, you would need to open the window using a JSNI method, so that
you can get the window handle:

native JavaScriptObject openWindow(String url) /*-{
return $wnd.open(url, '_blank');
}-*/;

In the other app, you would want to 'register' a function to receive
messages:

native void registerListener(String function) /*-{
$wnd[function] = function(arg) {
// Probably want to do something more interesting.
$wnd.alert('Received: ' + arg);
};
}-*/;

Then in the first app, you can write a simple function to call across
the boundary:

native void sendSomething(JavaScriptObject wnd, String function,
String arg) /*-{
wnd[function](arg);
}-*/;

Then in your first app, you would write something like:

JavaScriptObject otherWindow = openWindow("otherWindow.html");
sendSomething(otherWindow, "myListener", "blah");

And in the target app, you would want to register the listener function
in your onModuleLoad():

registerListener("myListener");

I realize all of this might seem a little crazy, but it seems to me
like something that we might be able to build in to the toolkit more
'officially' in the future.

joel.

Vikas Thakur

unread,
Jun 29, 2006, 9:42:08 AM6/29/06
to Google Web Toolkit
Thanks a lot joel. Now we have switched our design so that we are doing
everything in the same window but i am sure this will be very helpful
in future.

Vikas.

Reply all
Reply to author
Forward
0 new messages