Stan Kurilin
Stan Kurilin

Reputation: 15792

Simple question about custom method in RequestFactory

I have RequestFactory with some request interface

public interface FooRequest extends RequestContext {
   Request<List<Foo>> findSmt();
}

I can't figure out where I should place findSmt() implementation and how I should do wiring with that implementation.

Upvotes: 0

Views: 285

Answers (2)

Buhake Sindi
Buhake Sindi

Reputation: 89169

For Binding of the findSmt(), the documentation on GWT-RPC states.

The RequestFactory service stubs must extend RequestContext and use the @Service annotation to name the associated service implementation class on the server. The methods in a service stub do not return entities directly, but rather return subclasses of com.google.gwt.requestfactory.shared.Request. This allows the methods on the interface to be invoked asynchronously with Request.fire() similar to passing an AsyncCallback object to each service method in GWT-RPC.

Example:

@Service(Foo.class)
public interface FooRequest extends RequestContext {
   Request<List<Foo>> findSmt();
}

public interface FooRequestFactory extends RequestFactory {

    FooRequest fooRequest();
}

Finally, wiring

final EventBus eventBus = new SimpleEventBus();
requestFactory = GWT.create(FooRequestFactory.class);
requestFactory.initialize(eventBus);
FooRequest request = requestFactory.fooRequest();
request.findSmt().fire(new Receiver() {

    @Override
    public void onSuccess(void arg0) {
    //My implementation comes here....  

    }
});

The fire() is where you wire your findSmt().

Upvotes: 0

Riley Lark
Riley Lark

Reputation: 20890

You can use the @Service annotation to denote a class that implements findSmt. You should not inherit FooRequest.

@Service(FooRequestImpl.class)
public interface FooRequest extends RequestContext {
   Request<List<FooProxy>> findSmt();
}

...

public class FooRequestImpl
{
    List<FooDAO> findSmt()  //note that we dropped the Request and changed the Proxy to the DAO
    {
        return getFoos();
    }
}

Unfortunately in same cases I have been forced to put static methods in my domain entities. I think it is not possible to create an InstanceRequest in a separate class.

Upvotes: 1

Related Questions