Hello:

Just started using GWT and I am having difficult tailoring my code to
the asynchronous nature of RPC calls.  Specifically, my code asks for
the results of an RPC call before anything is returned.

Here is my class which calls a service.  Instead of using an inner
class for the AsyncCallback, I use a separate implementation,
FormAsyncCallback, whose code is also below:


package com.gallup.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public class FormService {

        public String call(FormBean formBean) throws FormException{

                FormRemoteServiceAsync serviceProxy = (FormRemoteServiceAsync)
GWT.create(FormRemoteService.class);
                ServiceDefTarget target = (ServiceDefTarget) serviceProxy;

                String serviceURL = GWT.getModuleBaseURL() + "formservice";
                if (GWT.isScript()) {
                        serviceURL = "/Struts2GWT/formservice";
                }
                target.setServiceEntryPoint(serviceURL);

                final String successMessage = null;

                FormAsyncCallback callback = new FormAsyncCallback();

                serviceProxy.setForm(formBean, callback);

                if (!callback.isHadError()) {
                        GWT.log("AAAAA", null);
                        return callback.getSuccessMessage();
                }
                else {
                        throw new FormException(callback.getErrorMessage());
                }
        }

}


package com.gallup.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class FormAsyncCallback implements AsyncCallback {


        private String successMessage = null;
        private boolean hadError = false;
        private String errorMessage = null;

        public void onFailure(Throwable t) {
                hadError = true;
                GWT.log("BBBBBBBB", null);
                errorMessage = t.getMessage();
        }

        public void onSuccess(Object result) {
                GWT.log("CCCCCCCCC", null);
                successMessage = (String) result;

        }

        public String getSuccessMessage() {
                return successMessage;
        }

        public boolean isHadError() {
                return hadError;
        }

        public String getErrorMessage() {
                return errorMessage;
        }
        public boolean isReturned() {
                return returned;
        }

}



My problem is that "AAAAAAA"  always prints before "BBBBB" or
"CCCCCCC".   I really want my code to wait for the RPC call to return
before I interrogate the results.  Does anybody have suggestions?

Thanks
Eric
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to