Equivalent to javascript confirmdialog ind GWT

978 views
Skip to first unread message

Dominic Warzok

unread,
Dec 17, 2012, 6:28:39 AM12/17/12
to google-we...@googlegroups.com
Hey together, 

I try about a day to find an equvalent to the javascript confirm-dialog. 

My problem is that when the user reload the webpage, he should get a dialog with a "Yes" and a "No" button where he can decide to only reload the page or to log off from the page. 

I found a jQueryUi Dialog but this dilog don't interrup the reload process. 

After this I found this Project but I can't call it from a native Method... 

Maybe someone of you know a solution ? 

Thanks in advance ;) 
Dominic 

Aldin Habibović

unread,
Dec 17, 2012, 6:31:43 AM12/17/12
to google-we...@googlegroups.com
Why don't use DialogBox?


Dominic 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/gT9Oh2s-gK4J.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Dominic Warzok

unread,
Dec 17, 2012, 6:41:24 AM12/17/12
to google-we...@googlegroups.com
Because the Dialog Box don't interrup the reload process. The Dialog Box is shown but then it disapears when the page is reloading. 


On Monday, December 17, 2012 12:31:43 PM UTC+1, Aldin wrote:
Why don't use DialogBox?
On Mon, Dec 17, 2012 at 12:28 PM, Dominic Warzok <dom...@googlemail.com> wrote:
Hey together, 

I try about a day to find an equvalent to the javascript confirm-dialog. 

My problem is that when the user reload the webpage, he should get a dialog with a "Yes" and a "No" button where he can decide to only reload the page or to log off from the page. 

I found a jQueryUi Dialog but this dilog don't interrup the reload process. 

After this I found this Project but I can't call it from a native Method... 

Maybe someone of you know a solution ? 

Thanks in advance ;) 
Dominic 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/gT9Oh2s-gK4J.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

Aldin Habibović

unread,
Dec 17, 2012, 6:46:15 AM12/17/12
to google-we...@googlegroups.com
You actually need this https://sites.google.com/site/develop4experts/tips-and-tricks/dontleavethispage , right? But implemented in GWT?

Dominic Warzok

unread,
Dec 17, 2012, 6:51:45 AM12/17/12
to google-we...@googlegroups.com
Yes this is right. At the Moment we use: 
 @Override
  public void onWindowClosing( ClosingEvent in_event )
  {
boolean confirm = Window
          .confirm("Do you want to leave this Page?");
 }

This takes the same effect but the Dialog is not editable.  

Aldin Habibović

unread,
Dec 17, 2012, 6:55:27 AM12/17/12
to google-we...@googlegroups.com
So, you want to reload the page or redirect the user to another page if user click "Leave this Page". If user click "Stay on this Page" the Dialog have just to close?

Dominic Warzok

unread,
Dec 17, 2012, 6:57:40 AM12/17/12
to google-we...@googlegroups.com
Yes if the user click on leave this page, he will be logged out of the application (Maybe redirect). If he click on stay the page will only be reload.  

Aldin Habibović

unread,
Dec 17, 2012, 7:13:11 AM12/17/12
to google-we...@googlegroups.com
Are you try using History. Every time when user reload the page it is a new history token. Thean you can use this methods for reloading the entire page:  com.google.gwt.user.client.Window.Location.reload() or  com.google.gwt.user.client.Window.Location.replace(newURL);


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/SF1pZcGHczIJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

Dominic Warzok

unread,
Dec 17, 2012, 7:19:49 AM12/17/12
to google-we...@googlegroups.com
No I' not using the history and in my opinon this is not necessary. 

The way this should go is. 

The user press "F5" or "Crlt + R" than the dialog should appear and the user can decide to log of or to continue the reloading of the page.

So there is no need to use the history. 


To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

Aldin Habibović

unread,
Dec 17, 2012, 7:35:50 AM12/17/12
to google-we...@googlegroups.com
If you don't use History, you can use jQuery/JavaScript. I guess this is the only solution. Do you really need this in your app project?


To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/YXi-A_OTOPcJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

Dominic Warzok

unread,
Dec 17, 2012, 8:15:10 AM12/17/12
to google-we...@googlegroups.com
Yes I really use it because it should be a security feature. 

And now the question how to implement this in JS 


On Monday, December 17, 2012 1:35:50 PM UTC+1, Aldin wrote:
If you don't use History, you can use jQuery/JavaScript. I guess this is the only solution. Do you really need this in your app project?
On Mon, Dec 17, 2012 at 1:19 PM, Dominic Warzok <dom...@googlemail.com> wrote:
No I' not using the history and in my opinon this is not necessary. 

The way this should go is. 

The user press "F5" or "Crlt + R" than the dialog should appear and the user can decide to log of or to continue the reloading of the page.

So there is no need to use the history. 



On Monday, December 17, 2012 1:13:11 PM UTC+1, Aldin wrote:
Are you try using History. Every time when user reload the page it is a new history token. Thean you can use this methods for reloading the entire page:  com.google.gwt.user.client.Window.Location.reload() or  com.google.gwt.user.client.Window.Location.replace(newURL);
On Mon, Dec 17, 2012 at 12:57 PM, Dominic Warzok <dom...@googlemail.com> wrote:
Yes if the user click on leave this page, he will be logged out of the application (Maybe redirect). If he click on stay the page will only be reload.  


On Monday, December 17, 2012 12:55:27 PM UTC+1, Aldin wrote:
So, you want to reload the page or redirect the user to another page if user click "Leave this Page". If user click "Stay on this Page" the Dialog have just to close?

On Mon, Dec 17, 2012 at 12:51 PM, Dominic Warzok <dom...@googlemail.com> wrote:
boolean confirm = Window
          .confirm("Do you want to leave this Pa

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/SF1pZcGHczIJ.

To post to this group, send email to google-we...@googlegroups.com.

To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Thomas Broyer

unread,
Dec 17, 2012, 9:43:39 AM12/17/12
to google-we...@googlegroups.com


On Monday, December 17, 2012 12:28:39 PM UTC+1, Dominic Warzok wrote:
Hey together, 

I try about a day to find an equvalent to the javascript confirm-dialog.

Window.confirm() ?

My problem is that when the user reload the webpage, he should get a dialog with a "Yes" and a "No" button where he can decide to only reload the page or to log off from the page.

In that specific case, you'll want to Window.addClosingHandler and setMessage on the event.

Dominic Warzok

unread,
Dec 17, 2012, 9:50:44 AM12/17/12
to google-we...@googlegroups.com
Window.confirm()?

We use this at the moment but there you can't change the buttons. In this confirm Dialog only "OK" or ´"Cancel" is avaible.

In that specific case, you'll want to Window.addClosingHandler and setMessage on the event.

We also have this handler added and it works well. Butt what do you mean with "setMessage"?

  

Thomas Broyer

unread,
Dec 17, 2012, 10:08:01 AM12/17/12
to google-we...@googlegroups.com

“Set the message to a non-null value to present a confirmation dialog that asks the user whether or not she wishes to navigate away from the page.” 

This is standard JS, the browser is left in control of how exactly it displays the message, but that's the only way to possibly prevent an "unload" of your app.

Dominic Warzok

unread,
Dec 17, 2012, 10:41:41 AM12/17/12
to google-we...@googlegroups.com
Yeah that's nice it's something we are looking for. But how do I interupt the thread.

I have implemented this in my webapp but now if the user reload the Page he will also be logged out when he click on "Stay".

Maybe I can attatch a callback or so ? 

Dominic Warzok

unread,
Dec 17, 2012, 10:59:11 AM12/17/12
to google-we...@googlegroups.com
I have fixed it :-) 

A lot of  thanks to Aldin, for your Ideas and your help. 

And  also to Thomas you have shown me the right way ;-) 

The solution is: There is a closingEvent which is be called when someone want to close the window. 

And there is a CloseEvent which is called when the window realy be closed. 

So my Question is be implementd in the onWindowClosing method and my logoutcode in the onClose method 


Thanks for your help 

Aldin Habibović

unread,
Dec 17, 2012, 11:00:13 AM12/17/12
to google-we...@googlegroups.com
Thank you :) Can you show us your solution :)


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/tTgcYhTkOc0J.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

Aldin Habibović

unread,
Dec 17, 2012, 11:00:39 AM12/17/12
to google-we...@googlegroups.com
I mean the source code :D

Dominic Warzok

unread,
Dec 17, 2012, 11:10:52 AM12/17/12
to google-we...@googlegroups.com
The solution is posted her on Stackoverflow

And here is my code (it's only a extract of the full class) :

public class MainPresenter<V extends MainView>
    extends BasicPresenter<V>
    implements HistoryTokens, MainViewControl, LoginEventHandler, Window.ClosingHandler,
    CloseHandler<Window>
{
 ....
 Window.addWindowClosingHandler( this );
    Window.addCloseHandler( this );

....

  /**
   * Diese Methode wird naufgerufen wenn das Browsertab geschlossen werden soll
   */
  @Override
  public void onWindowClosing( ClosingEvent in_event )
  {
    if ( model.isUserlogin() )
    {
      in_event.setMessage( CONSTANTS.web_client_MainPresenter_AenderungenSpeichernHinweis() );
    }
  }

  /**
   * Diese Methode wird naufgerufen wenn das Browsertab geschlossen wird
   */
  @Override
  public void onClose( CloseEvent<Window> event )
  {
    if ( model.isUserlogin() )
    {
      camWebServiceAsync.logout( new AsyncCallback<Void>()
      {

        @Override
        public void onSuccess( Void in_result )
        {
          
        }

        @Override
        public void onFailure( Throwable in_caught )
        {
        }
      } );
    }
  }

}

Milan Cvejic

unread,
Dec 18, 2012, 10:40:47 PM12/18/12
to google-we...@googlegroups.com
You could use event.preventDefault() in onWindowClosing method,
display custom dialog box and if user confirmed close logout him.

Best,
Milan

RyanZA

unread,
Dec 19, 2012, 2:43:36 AM12/19/12
to google-we...@googlegroups.com
Hey

The 'proper' way to do the confirm dialog is to use the Activies and Places framework in GWT.

https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#Activities

    /**
     * Ask user before stopping this activity
     */

   
@Override
   
public String mayStop() {
       
return "Please hold on. This activity is stopping.";
   
}

Thomas Broyer

unread,
Dec 19, 2012, 4:56:42 AM12/19/12
to google-we...@googlegroups.com


On Wednesday, December 19, 2012 8:43:36 AM UTC+1, RyanZA wrote:
Hey

The 'proper' way to do the confirm dialog is to use the Activies and Places framework in GWT.

Activities' mayStop relies on PlaceChangeRequestEvent. PlaceChangeRequestEvent is dispatched both when navigating within the app (which the OP didn't ask) and when unloading, in which case it relies on Window.addClosingHandler.
So the 'proper' way really is to use Window.addClosingHandler.

RyanZA

unread,
Dec 19, 2012, 5:33:15 AM12/19/12
to google-we...@googlegroups.com
Thanks Thomas, clears it up.

As an aside, is there a way to work out which event the mayStop() is being called for? So you could decide whether to show the message if the user is closing the browser or navigating to Place A, but not if he is navigating to Place B?
eg. If the user is filling out a form and presses help we would want to save the form state and let him go there, but if the user is closing the form or navigating somewhere else in the webapp, we'd want to show him the message (to let him know he hasn't saved the form, etc)?

ie. can the source event be caught somehow?

Thomas Broyer

unread,
Dec 19, 2012, 5:42:31 AM12/19/12
to google-we...@googlegroups.com


On Wednesday, December 19, 2012 11:33:15 AM UTC+1, RyanZA wrote:
Thanks Thomas, clears it up.

As an aside, is there a way to work out which event the mayStop() is being called for? So you could decide whether to show the message if the user is closing the browser or navigating to Place A, but not if he is navigating to Place B?
eg. If the user is filling out a form and presses help we would want to save the form state and let him go there, but if the user is closing the form or navigating somewhere else in the webapp, we'd want to show him the message (to let him know he hasn't saved the form, etc)?

Add a PlaceChangeRequestEvent.Handler to the EventBus and don't bother with mayStop.

RyanZA

unread,
Dec 19, 2012, 5:55:47 AM12/19/12
to google-we...@googlegroups.com
Awesome, thanks!
Reply all
Reply to author
Forward
0 new messages