Window.confirm/alert is pretty much the only thing that can halt Javascript
execution.
You have to refactor your code a bit. Instead of
public boolean doPost(String url, String postData)
you should use
public void doPost(String url, String postData, Callback<..., ...>
callback) {
dlg.show();
builder.sendRequest(postData, new RequestCallback() {
void onError(....) {
dlg.hide();
callback.onFailure(...);
}
void onResponseReceived(...) {
dlg.hide();
if(statusCode == OK) {
callback.onSuccess(...);
} else {
callback.onFailure(...);
}
}
});
}
So everyone who calls your doPost() method has to provide a callback in
order to be notified when the post succeeds or fails. You have to think
asynchronous :-) The only thing that makes sense to return in that case is
the Request instance created by builder.sendRequest(...), so the calling
code can cancel the request if needed:
public Request doPost(..., Callback callback) {
dlg.show();
return builder.sendRequest(...);
}
-- J.
Am Montag, 5. September 2011 19:01:29 UTC+2 schrieb melody:
>
> I wish to embed an asynchronous call to the server inside a method
> that MUST NOT return until the server has responded. So I am looking
> for a way to achieve a non-busy wait in GWT. I thought I could use a
> modal popup dialog to stop the next line from being executed until the
> dialog is closed and only after the response from server arrives.
> Unfortunately the GWT modal dialog does not do what I thought it would
> do -- which is block everything and wait at the line where the
> PopupPanel.show() method is called. See method below
>
> <code>
> public boolean doPost(String url, String postData) {
> RequestBuilder builder = new
> RequestBuilder(RequestBuilder.POST, url);
> final int STATUS_CODE_OK = 200;
> final PopupPanel dlg = new PopupPanel();
> dlg.setModal(true);
> dlg.setGlassEnabled(true);
> try {
> builder.setHeader("Content-Type", "application/x-www-form-
> urlencoded");
> builder.sendRequest(postData, new RequestCallback() {
> public void onError(Request request, Throwable
> exception) {
> dlg.hide();
> }
>
> public void onResponseReceived(Request request,
> Response response) {
> int li_status = response.getStatusCode();
> if (li_status == STATUS_CODE_OK) {
> //bravo
> }
> dlg.hide();
> }
> });
> builder.setTimeoutMillis(3000);
> dlg.show();
> return true;
> } catch (RequestException e) {
> GWT.log(e.getLocalizedMessage());
> }
> return false;
> }
> </code>
>
> I want the line
>
> <code>
> return true;
> </code>
>
> to be executed only after the dialog is closed just like what would
> happen if I used Window.confirm to achieve the modality as shown
> below.
>
> <code>
> Window.confirm("yes or no");
> return true;
> </code>
>
>
> Any ideas on how I can achieve this.
>
>
> Thanks,
>
> Melody
>
>
--
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/-/eaTWtayq7tkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.