Call a GWT method from a web page in an other frame

117 views
Skip to first unread message

gronk

unread,
Mar 30, 2007, 9:59:01 AM3/30/07
to Google Web Toolkit
Hello,

I read a few posts which trea tmore or less my problem, but I don't
find a solution.

My web page is made of 2 frames :

- On the left is displayed a GWT Tree
- On the right can display some JSP pages.

Thanks to the GWT Tree, I can display (<a href="http://..."
target="right">text</a>) the JSP pages in the right frame. But I would
like when one of those pages is displayed, it calls (from the page
displayed) a method written in a Java class (why not a constructor ?).


I don't know how to do this :-\

So, if someone can help me, it was great.

Thanks.

echo

unread,
Apr 2, 2007, 2:42:20 AM4/2/07
to Google Web Toolkit
i have the same problem with you...
why nobody answer... T_T

gronk

unread,
Apr 2, 2007, 3:48:44 AM4/2/07
to Google Web Toolkit
Maybe, it's impossible :-(

ckornelis

unread,
Apr 2, 2007, 11:38:16 AM4/2/07
to Google Web Toolkit
This is possible to do, but is not supported directly by GWT. The
"easy" way to do this would be to output into pretty or detailed,
since these methods will produce generally knowable method names, and
you can then invoke these methods by obtaining the window the GWT code
is running in (remember it is always in an iframe inside the page).
The nasty part of this is that you are sidestepping the compiler, and
thus, and changes to the signature of the method you are calling, and
invoking anything outside of the static context begins to border on
the painful, though is entirely possible.

The 'alternative' would be to have a native method that defines a
function in the parent window that calls the proper method in your
app. The advantage here is the compiler will do all the right linking
for you, leaving just have to call the newly defined javascript method
in the parent window, and it will route through to your GWT app.
Downside is, you basically have to write a callback method into the
parent window for each exposed method you want.

example:

lets assume your main window has a object declared called
'gwtCallback' which simply acts as a binding point for methods you
want to write, while there are other ways to do this certainly, the
important part is that you can easily locate and invoke the method you
write without fear of breaking things.

native void writeCallback() /*-{
function __someFunctionName(...) {
...//any sort of setup you need to do, or handling parameters
@package.Class::method(...)(...);
...
}
$wnd.gwtCallback.someFunctionName = __someFunctionName;
}-*/

now just invoke your method, assuming that writeCallback has at some
point been called from within GWT (just place it in your onModuleLoad
or in a static init). This always feel like a hack, so I wouldn't use
it extensively, but it will get the job done

Dan Morrill

unread,
Apr 2, 2007, 4:29:46 PM4/2/07
to Google-We...@googlegroups.com

Hello!

Here are some links to previous discussions that may help you:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/78f076de79a95ec7/45407f2c0292906f?lnk=gst&q=bridge&rnum=7#45407f2c0292906f
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f1127607f701b75e/bd36c51f601b96c5?lnk=gst&q=well-known&rnum=2#bd36c51f601b96c5

Also, here is an FAQ that provides a basic answer to your questions:
http://code.google.com/support/bin/answer.py?answer=55953&topic=10213

The key difference in your scenario is that you are communicating across windows.  This requires a little bit of extra work to set up, but is in general very similar to the basic scenario.  The second Forum posting above describes a slightly different version of that case.

Hope that helps!

- Dan Morrill

Brill

unread,
Apr 2, 2007, 5:53:22 PM4/2/07
to Google Web Toolkit
Can you assign widgets to nodes (if not, I know there is an extension
that has a tree like that but I don't remember its name).
then simply use an HTML widget and specify the target attribute:

HTML link1 = new HTML("<a href=\"x.com/page.jsp\" target=\"frameName
\">Link Text</a>");

All you need to be able to do is specify the tree node as HTML so you
can write out that link.

- Brill Pappin

gronk

unread,
Apr 3, 2007, 5:15:03 AM4/3/07
to Google Web Toolkit
Thanks for your answers.

Now, I would launch the execution of the someFunctionName() function
from independant JSP page.

So, to reach the function, which file must I include ? (gwt.js,
myApp.html, ...)

I saw the function is in several files.

I don't know which file I must include :-\

gronk

unread,
Apr 3, 2007, 9:24:32 AM4/3/07
to Google Web Toolkit
Entry point :

public void onModuleLoad()
{
RootPanel.get().add(this);
new MyClass().display();
}


pabkage test;

public class MyClass

public static void view(String word)
{
Window.alert(word);
}

public native void display()
/*-{
$wnd.view = function(word)
{
return @test.MyClass::view(Ljava/lang/String;)(word);
}
}-*/;
}

HTML file :

<html>
...
...
<script language="javascript" src="gwt.js"></script>
<script>view('gronk');</script> <!-- I added this line -->
</html>


When I open the window, there is an error message in the error
console :

view is not defined.

So, how can I execute the display function or what is wrong ?

Message has been deleted

Reinier Zwitserloot

unread,
Apr 3, 2007, 3:10:57 PM4/3/07
to Google Web Toolkit
That won't work, because at the time you call view('gronk'), no GWT
code has even run yet.

You'll need to hook something back to make this work. Try this: update
some div (don't use an alert, it screws up timing)'s text as very
first line in your GWT entry point, and modify another div right
before you call view('gronk'), with both adding milliseconds (new
Date().valueOf() in JS, new Date().getTime() in GWT - they are the
same thing) to these divs. You'll find that the 'view('gronk') div has
a timestamp that will be older than the entry point.

gronk

unread,
Apr 4, 2007, 4:57:45 AM4/4/07
to Google Web Toolkit
"That won't work, because at the time you call view('gronk'), no GWT
code has even run yet."

Thank you very much for your answer. It's something to know.


Now, I can call the view() function from the right frame to the left
frame :

<html>
<body onload="parent.frames['left'].view('gronk');"></body>
...
</html>

Thank you Reinier Zwitserloot !

Reply all
Reply to author
Forward
0 new messages