GWT 2.1.1 Multiple method calls on Single Request example

43 views
Skip to first unread message

-sowdri-

unread,
Dec 17, 2010, 11:04:38 PM12/17/10
to Google Web Toolkit
Dear All,

Glad to see the new GWT release, more explanation or working example
of

>>Multiple methods calls on a single request

would be great!

Thanks in advance,
-sowdri-

AutoBean von AutoBahn

unread,
Dec 18, 2010, 1:06:57 AM12/18/10
to Google Web Toolkit
+1000

Thomas Broyer

unread,
Dec 18, 2010, 5:11:50 AM12/18/10
to google-we...@googlegroups.com
What it means is that for a given RequestContext, you can now call more than one method on it before fire()ing. This was not possible in GWT 2.1.0, where only one invocation could be done.
For instance, if I want to create 10 objects in one go, assuming 'factory' is a RequestFactory, Context is a RequestContext and DomainProxy is an EntityProxy (or ValueProxy):
  Context context = factory.context();
  for (int i = 0; i < 10; i++) {
    DomainProxy domain = context.create(DomainProxy.class);
    domain.setIndex(i);
    context.persist().using(domain).to(new Receiver<Boolean>() {
      public void onSuccess(Boolean response) {
        // this will be called for each domain object being persisted
        // assuming the persist method returns a boolean here, but could be whatever you want
      }
    });
  }
  context.fire(new Receiver<Void>() {
    public void onSuccess(Void response) {
      // this will be called once only for the whole "create 10 objects" "batch" request
    }
  });

The to() is optional, as is the receiver in the final context.fire(). The request is sent to the server only when calling a fire() method. Calling a fire() on a Request or InstanceRequest is a short-hand to using .to() and then immediately calling .fire() on the RequestContext.
Reply all
Reply to author
Forward
0 new messages