Search code examples
gwtgwt-rpcrequestfactory

RequestFactory with service layer


I need to use GWT with a service-based domain layer - not beans with DAOs. Is the GWT 2.1 architecture with MVP and RequestFactory fitted for this? Or should I stay with RPC?

Thanks


Solution

  • GWT 2.1.1 adds a Locator and ServiceLocator mechanism to allow you to control how the RequestFactory server code obtains references to entities and service object instances.

    For example, you can declare code like

    class MyService.class {
      // Note that this is not a static method
      public void doSomething() {....};
    }
    
    class MyServiceLocator implements ServiceLocator {
      public Object getInstance(Class<?> clazz) {
        // Or use Guice, Spring, whatever provides instances of MyService
        return new MyService();
      }
    }    
    
    interface MyRequestFactory extends RequestFactory {
      @Service(value=MyService.class, locator=MyServiceLocator.class)
      interface ServiceRequest extends RequestContext {
        Request<Void> doSomething();
      }
      ServiceRequest myService();
    }
    

    If you need even more control over how RequestFactory interacts with your server domain objects or service code, you can inject instances of ServiceLayerDecorator into the service layer.