Re: Modal Dialog/Non-busy Wait

2012-12-08 Thread Jens
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 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.



Re: Modal Dialog/Non-busy Wait

2012-12-07 Thread Rob


On Monday, September 5, 2011 1:01:29 PM UTC-4, melody wrote:

 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/-/CHczoRW3l8EJ.
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.



Modal Dialog/Non-busy Wait

2011-09-05 Thread 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 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.