异步回调可以保存值,但会打印FAILED

时间:2010-03-18 23:44:20

标签: gwt asynchronous callback asynccallback

我正在使用嵌套的异步回调将我的前端数据保存到后端数据库。数据以我希望的方式保存到表中,但是打印失败了。这是代码:

    if(erasync == null)
        erasync = GWT.create(EntityRelationService.class);
    AsyncCallback<Void> callback = new AsyncCallback<Void>(){
        public void onFailure(Throwable caught) {
            String msg = caught.getLocalizedMessage();
             if (caught instanceof NotFoundException) {
                msg = ((NotFoundException) caught).getType()
                      + ((NotFoundException) caught).getMessage();
             }
           System.out.println("Failed" + msg);
        }
        public void onSuccess(Void result) {
                    if(erasync == null)
                        erasync = GWT.create(EntityRelationService.class);
                    AsyncCallback<Void> callbackOthers = new AsyncCallback<Void>(){
                        @Override
                        public void onFailure(Throwable caught) {
                            String msg = caught.getLocalizedMessage();
                             if (caught instanceof NotFoundException) {
                                msg = ((NotFoundException) caught).getType()
                                      + ((NotFoundException) caught).getMessage();
                             }
                           System.out.println("Failed" + msg);
caught.printStackTrace();
                        }
                        public void onSuccess(Void result) {
                            System.out.println("Success");
                        }                           
                    };
                    erasync.setEntityType(name, top, left, pname, callbackOthers);
        };
        erasync.setProject(name, callback);

这里它为第一个回调打印成功,但是对于嵌套的回调,它表示失败但它保存了值。这是它打印失败的堆栈:

com.google.gwt.user.client.rpc.StatusCodeException: 
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
    at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    at java.lang.Thread.run(Thread.java:619)

我错过了什么吗?

任何输入都会有很大的帮助。 谢谢。

1 个答案:

答案 0 :(得分:1)

嘿,我解决了这个问题。我遇到了这个问题,因为窗口正在重新加载并在进程中仍有异步调用时更改状态代码。我在方法结束时包含了窗口重载,现在工作正常。谢谢大家。