Search code examples
gwtgxtjsni

Multiple Browser Window Communication with GWT or GXT


I am building a system that will be used in a corporate environment as the users' primary working environment. We'd like to be able to open a second browser window for certain functionality and have the 2 windows communicate (eg. browse a mapping interface on one, select an object and open it in an editor on the other window). I've got 2 options that I can come up with:

1) Attempt to implement some JSNI methods to obtain a handle on the Window and communicate in this way.

2) Implement a long-polling server to pass events with a shared session via a cookie

Are there any examples or suggestions on how to go about achieving option 1? I'm using GWT and GXT.

Or, do you have another suggestion on how to achieve multiple browser communication?


Solution

  • Thanks for the suggestions. We plan to revisit our navigation mechanism and Activities and Places looks like a very tidy way of doing things. For now, we navigate via Events fired against an EventBus, which a Navigation class listens to and directs navigation accordingly.

    I've got the communication happening via JSNI. However, I'm having an annoying issue with it. The new window makes a call:

    public native void fireCrossBrowserEvent(GwtEvent<?> event) /*-{
        $wnd.opener.fireCrossBrowserEvent(event);
    }-*/;
    

    Which calls this method in the main window:

    $wnd.fireCrossBrowserEvent = $entry(function(event) {
        $wnd.alert("fireCrossBrowserEvent: " + event);
        @my.application.client.event.EventBus::fireEvent(Lcom/google/gwt/event/shared/GwtEvent;)(event);
    });
    

    which calls:

    public static void fireEvent(GwtEvent<?> event) {
        System.out.println("fireEvent: " + event);
        bus.fireEvent(event);
    }
    

    I ended up using google AutoBean to synchronise and desynchronise the events for sending via JSNI. All works nicely. Also, for communication back to the child window, I had to create a new Native method to replace GWT's Window.open method so that it returns a reference to the new window. The javascript function returns the reference to the new window, but for some reason, GWT's wrapper returns void.