1 Reply Latest reply on Sep 20, 2013 4:19 PM by John DeStefano

    Bus process in onWindowClosing event

    John DeStefano Apprentice

      Hi,

       

      I'm trying to send a message using CDI back to the server when the user reloads the page. I catch the reload in a WindowClosingHandler:

       

      Window.addWindowClosingHandler(new ClosingHandler() {

        @Override

        public void onWindowClosing(ClosingEvent event) {

        if (clientUserToken.isLoggedIn() == true) {

        logoutRequestEvent.fire(new LogoutRequestEvent(false));

        }

        }

        });

       

      The event never reaches the server. It looks like the bus is destroyed? Any ideas. I can work around it with this but its somewhat confusing for the users:

       

       

      Window.addWindowClosingHandler(new ClosingHandler() {

        @Override

        public void onWindowClosing(ClosingEvent event) {

        if (clientUserToken.isLoggedIn() == true) {

        logoutRequestEvent.fire(new LogoutRequestEvent(false));

        event.setMessage("You will be logged out of Olhie. Thanks, come again!");

        }

        }

        });

       

      In this case the event does get fired.

       

       

      Thanks

        • 1. Re: Bus process in onWindowClosing event
          John DeStefano Apprentice

          Hi,

           

          I've answered my own question but I'll post here in cast anyone else runs into a similar problem. At first I thought their might be some Erraii related issue with the bus closing down before the browser window actually closed. On further investigation, async calls happening in the main windows onCloseHandler where executing in FireFox and IE but not in Chrome. The purpose of the call was to log the user out if they were logged in when the window was reloaded, navigated away from, or the browser was closed.

           

          It seems that FireFox and IE does successfully run async calls in the close handler but Chrome does not. There are various bits and pieces of info on the web about this. To address this issue I used a native method that called a jQuery function to send a sync call to a rest service which logged the user out of the back end. It looks something like this:

           

          Window.addCloseHandler(new CloseHandler<Window>() {

            @Override

            public void onClose(CloseEvent<Window> event) {

            if (clientUserToken.isLoggedIn() == true) {

            // windowCloseService.call().windowCloseAction();

            windowCloseTrapped();

            }

            }

            });

           

          .............

           

          public static native void windowCloseTrapped() /*-{

            $wnd.jQuery.ajax({

            url : "/olhie/rest/windowclose/closeaction",

            async : false,

            contentType : "application/json; charset=utf-8",

            dataType : "json",

            data : ({}),

            type : "POST",

            success : function() {

            return true;

            },

            error : function() {

            alert('Error');

            }

            });

            }-*/;

           

           

          Hope this might be useful to others with a similar issue.

           

           

          Thanks