If the same is tried using Java, GWT throws a ClassCastException.
Although you use exactly the same method call with JavaScript native
code and Java code. The Java method call throws an exception but the
JavaScript native method call doesn't.
Example:
I have a Java object called "ClientSession". The module loaded in the
main window has the following code:
public class Main implements EntryPoint {
private static ClientSession clientSession = new ClientSession();
...
...
public Main() { }
public void onModuleLoad() {
exportClientSession();
...
(more code)
...
...
}
// JSNI to export clientSession object in "window.top".
private static native void exportClientSession() /*-{
$wnd.top.clientSession =
@GWTApplication.client.Main::clientSession;
}-*/;
}
The Main module has a button that opens the Second module in a new
browser window.
This second module has this code:
public class Second implements EntryPoint {
public Second() { }
public void onModuleLoad() {
// Make a new button that does something when you click it.
Button b = new Button("Show Main ID!", new ClickListener() {
public void onClick(Widget sender) {
showSession(); //
Don't throw ClassCastException.
ClientSession session = getSession(); // Throw
ClassCastException.
Window.alert(session.getId());
} });
RootPanel.get().add(b);
}
// This function works
private native void showSession() /*-{
var session = $wnd.opener.top.clientSession;
alert(session.@GWTApplication.client.ClientSession::getId()());
}-*/;
// This function throws an exception
private native ClientSession getSession() /*-{
var session = $wnd.opener.top.clientSession;
return session;
}-*/;
}
It's a nonsense.
I use native sintax to call a java method using JavaScript (JSNI):
session.@GWTApplication.client.ClientSession::getId()()
And it works, but if I try the same method call from Java it doesn't
work:
ClientSession session = getSession(); // throw ClassCastException
Window.alert(session.getId());
Is this a GWT bug?
> alert(sessi...@GWTApplication.client.ClientSession::getId()());
> }-*/;
>
> // This function throws an exception
> private native ClientSession getSession() /*-{
> var session = $wnd.opener.top.clientSession;
> return session;
> }-*/;
>
> }It's a nonsense.
>
> I use native sintax to call a java method using JavaScript (JSNI):
>
> sessi...@GWTApplication.client.ClientSession::getId()()
But how I implements communication across browser windows? Even the
open method of the GWT Window object doesn't return anything.
I tried to open a new window with "$wnd.open" in a JSNI native method
to get a reference to the new window and then pass my object reference
to this new window, but I get the same exception.
I've been looking for how implement communication across windows, I
didn't find anything but use JavaScript, and then GWT loses part of its
usefulness.
And I wonder why I can use the same instance using JSNI sintax to
access Java Object, but I cannot use Java code.
Is there anything to communicate windows and still using GWT? I have an
AJAX application that I want convert in a GWT application, but it's
essential windows communication because I implement a "browser session
pattern" shared across all windows, what is an important advantage of
AJAX.
Is there any way to use the same typeId for the same class in two
diferents windows?
Thank you.
mP ha escrito:
What have JRE classes got to work well across windows? What must my
classes have to work well? If anyone has a solution, please tell me.
But we finally found out that it works well in Web Mode and fails just
in Hosted Mode.
Therefore it isn't a problem about the GWT Compiler. It's just a
problem about the embedded browser (GWTShell).
Although it's work well in Web Mode, it's difficult to test the code if
we can't use the Hosted Mode.
I hope someone find out how to patch the GWTShell and then allow us to
do in Hosted Mode what we can do in Web Mode.
Thanks
Was this issue ever posted on the issues list?
I'm having exactly the same problem now...
I'm sorry but I've been absent a long time and I couldn't pursue this
subject.
I don't know if someone has already posted it on the inssues list so
I'll post it today.
Thank you