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.
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
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
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 :-\
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 ?
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.
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 !