> I was wondering if anyone knows of a way to run a function after the
> RPC is complete.

The completion of a RPC call is signaled by the call to the onSuccess
method of the asyncCallback you pass to the RPC as the last argument.
So how does this answer your question ? Let's take a concrete example.
Let's say you call your rpc in the following way:

<code>
myRPCAsyncInstance.myMethodCall(parameter1, parameter2, ...,
parameterN, myCallback);
</code>

This is how you would implement your callback to call a method call
doSomethingWhenRpcIsFinished:

<code>
AsyncCallback<MyReturnObject> myCallback = new
AsyncCallback<MyReturnObject>(){
  //This is the method called when the RPC call failed
  public void onFailure(Throwable t){
    GWT.log("RPC failed");
  }

  //This is the method called when the RPC finished successfully
  public void onSuccess(MyReturnObject result){
    doSomethingWhenRpcIsFinished();
  }
};
</code>

Hope that helps,

Salvador

On May 15, 10:52 pm, JohnofLong <[email protected]> wrote:
> Thank you for your input, what was happening is once the RPC was
> complete the data that I was adding to the ArrayList would disappear.
> So I decided to do something ugly, but it works. I am writing the data
> onto a invisible div on the page then getting it then adding it to the
> ArrayList. It seems to work just fine.
>
> I am new to GWT but I am starting to get a basic understanding on how
> these things work.
>
> I was wondering if anyone knows of a way to run a function after the
> RPC is complete.
>
> Thanks!
>
> John
>
> On May 9, 7:44 am, Salvador Diaz <[email protected]> wrote:
>
> > Well, the indexOutOfBoundsException can't possibly be thrown by the
> > method add of an ArrayList (that's the type of productArrayList, isn't
> > it?). In fact there's nothing in your snippets that'll throw that
> > exception. Did you debug the method call on the server side ?
> > Somewhere in your Eclipse or HostedMode console you'll have a complete
> > stack trace that'll tell you the exact line of code that's throwing
> > that exception. I suggest you read it carefully.
>
> > As for the lifecycle of your RPCs, it is the normal lifecycle of a
> > servlet.
>
> > Hope that helps,
>
> > Salvador
>
> > On May 8, 10:46 pm, JohnofLong <[email protected]> wrote:
>
> > > I tried to find this topic already on the discussions but could not
> > > find it.
>
> > > Currently using  GWT 1.5.3
>
> > > I am making a RPC to call to read XML and call a function that loads
> > > the data into an ArrayList of classes. I have made a class that
> > > implements RequestCallback(LoadData) and takes in my mainClass
> > > example:
>
> > > LoadData loadData = new LoadData(this);
> > >                 String url = xmlString;
> > >             RequestBuilder requestBuilder = new RequestBuilder
> > > (RequestBuilder.GET, url);
> > >             try {
> > >               requestBuilder.sendRequest(null, loadData);
> > >             } catch (RequestException ex) {
> > >                 //Window.alert("exception");
> > >             }
>
> > > Inside the RPC class:
>
> > > mainClass.addProducts(id, sku, name, catagory) ;
>
> > > inside my main class:
> > > public addProducts(int id, int sku, String name, String catagory) {
> > >         productArrayList.add(new product(id, sku, name, catagory);
>
> > > }
>
> > > But when I call a method on my productArray it just says index out of
> > > bound (basically the arrayList is empty) but I know it is calling the
> > > addProduct method
>
> > > I am guessing the lifespan of the data is tied to the lifespan of the
> > > RPC call.
>
> > > What sort of things can I do to get around this(assuming my
> > > assumptions are correct)?
>
> > > I greatly appreciate the help and apologize if this topic is covered
> > > somewhere already.
--~--~---------~--~----~------------~-------~--~----~
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