I faced exactly the same problem (see
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/36979a4e8e51fdc5#
)
I concluded that in case of a refresh, the async call is cancelled in
the browser before it has concluded.
I solved the problem by "waiting" until the onSuccess() of the
callback was called. This waitingf is implemented by using a timer
that fires repeatdly until it is stopped in the
onSuccess() method of the RPC callback.
Here is the main piece of code
//code called in the ClosingHandler
final AsyncCompletionFlag flag= new AsyncCompletionFlag() ;
SessionGWTInterface.Util.getInstance().transfersSave(xml.toString(),
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
flag.setDone() ;
return ;
}
public void onSuccess(String result) {
flag.setDone() ;
return ;
}
}) ;
//We need to have this to be sure to continue running until the RPC
completes. If not, it can be cancelled before
//it acttually runs
AsyncCompletionChecker checker = new AsyncCompletionChecker(flag) ;
checker.run() ;
package eu.oobikwe.gwt.rpc;
import com.google.gwt.user.client.Timer;
public class AsyncCompletionChecker extends Timer{
private static int WAIT_TIME = 10 ;
private int waitTime ;
private AsyncCompletionFlag flag ;
public AsyncCompletionChecker(AsyncCompletionFlag flag) {
this(flag,WAIT_TIME) ;
}
public AsyncCompletionChecker(AsyncCompletionFlag flag,int waitTime)
{
super();
if(waitTime > 0) {
this.waitTime = waitTime;
}
else {
this.waitTime = WAIT_TIME ;
}
this.flag = flag ;
}
@Override
public void run() {
if(!flag.isDone()) {
this.schedule(waitTime) ;
}
}
}
package eu.oobikwe.gwt.rpc;
public class AsyncCompletionFlag {
private boolean done ;
public AsyncCompletionFlag () {
super() ;
done = false ;
}
public boolean isDone () {
return done ;
}
public void setDone() {
done = true ;
}
}
This works for me.
On 20 apr, 09:24, chill_hus <[email protected]> wrote:
> Hi
> I am working on an application which uses GWT 2.0, gwt-comet & GXT
> I have added a close handler (Window.addWindowClosingHandler) to
> detect refresh and closing of browser
> When this handler is called I do a RPC to a servlet.
> This RPC is executed properly if the browser tab is closed. However in
> case of refresh it is inconsistent. Few times RPC is executed while
> some times it doesn't and onFailure (of AsyncCallback) is called and
> StatusCodeException is thrown
> Is there any thing wrong in my implementation. pls help me out with
> this situation.
> Thanks in advance for suggestions
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> 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
> athttp://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
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.