Hi Paul,

There are several ways to resolve this situation and here is one of
them. It is a bit awkward solution and it may not fit correctly within
your surrounding logic (so you must be careful) but it is relatively
easy to setup:

Declare an instance boolean flag variable at the right place (let'
name it "isActionConfirmed") and make your code in method onBeforeClose
() check on this value to branch the logic in such a way that if the
action is confirmed then execute the action, reset the flag to false,
and return true from onBeforeClose().

If isActionConfirmed equals to false, then present an async modal
popup dialog (which captures a real user input) but return false from
onBeforeClose() in order to make the control flow stay where it is now
(and do nothing at this point). Having obtained the real action value
from user input you set the isActionConfirmed flag to true and invoke
the onBeforeClose() method on the widget again.

    @Override
    public boolean onBeforeClose() {
        if (isActionConfirmed) {
            executeSyncAction();
            isActionConfirmed = false; // Not any more! Reset.
            return true; // State is saved by now.
        } else {
            showAsyncModalPopup();
            // Code for popup will set the flag to true, if user wants
to save.
            return false; // Keep the control flow where it
is.
        }
    }

Once again, such a workaround may introduce errors, so be careful. For
example, if there is code following the return of onBeforeClose()
callback and it assumes that the data is always saved then there is a
problem because we do return from onBeforeClose() (with false value)
without neither saving data nor having the user input yet.

Would be interesting to know it it works for you.

On Apr 26, 2:52 pm, Paul Grenyer <paul.gren...@gmail.com> wrote:
> Hi
>
> Thanks for the response. Yes, what you say is very true. However, it
> doesn't help me. The problem I've got is that I have a method which is
> called just before a tab is closed. If the contents of the tab has
> been modified, but not saved, I want to pop up a yes/no/cancel box so
> that the user can save, not save or cancel the close option. If they
> cancel I need to return false from the original method, otherwise
> true. I don't think that can be done asychronously:
>
> public boolean doBeforeClose()
> {
>     boolean close = true;
>
>     // Show box and reset close.
>
>     return close;
>
> }
>
> Thanks
> Paul
>
>
>
> On Sat, Apr 25, 2009 at 10:54 PM, Vitali Lovich <vlov...@gmail.com> wrote:
> > Why does it have to be synchronous?  Not sure what kind of message box you
> > are referring to, but it's fairly trivial to convert a synchronous algorithm
> > to an asynchronous one.
>
> > // synchronous code
> > // message box
> > // synchronous code
>
> > instead make it
> > // synchronous code
> > // message box
> > // in asynchronous result from message box, continue with synchronous code.
>
> > On Sat, Apr 25, 2009 at 4:08 PM, Paul Grenyer <paul.gren...@gmail.com>
> > wrote:
>
> >> Hi All
>
> >> I'm using GWT 1.6 and gwt-ext and need a Yes/No/Cancel message box
> >> that is NOT asynchronous.
>
> >> Google isn't helping. Can anyone else point me in the right direction,
> >> please?
>
> >> Thanks!
>
> >> --
> >> Thanks
> >> Paul
>
> >> Paul Grenyer
> >> e: paul.gren...@gmail.com
> >> w:http://www.marauder-consulting.co.uk
> >> b: paulgrenyer.blogspot.com
>
> --
> Thanks
> Paul
>
> Paul Grenyer
> e: paul.gren...@gmail.com
> w:http://www.marauder-consulting.co.uk
> b: paulgrenyer.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to