Connecting gwt send with guice and mvp4g

I have some questions regarding gwt-dispatch and guice. I am using Guice 2.0, gwt-dispatch 1.1.0 snapshot, mvp4g 1.1.0 and GIN 1.0

First of all, I defined a simple action, result, and handler:

ListContactsAction.java

public class ListContactsAction implements Action<ListContactsResult>{

    public ListContactsAction() {
    }

}

ListContactsResult.java

public class ListContactsResult implements Result {

    private List<Contact> contactList;

    public ListContactsResult() {
    }

    public ListContactsResult(List<Contact> contactList) {
        this.contactList = contactList;
    }

    public List<Contact> getContactList() {
        return contactList;
    }
}

ListContactsHandler.java

public class ListContactsHandler implements ActionHandler<ListContactsAction, ListContactsResult>{

    @Inject
    private SqlSessionFactory factory;

    public Class<ListContactsAction> getActionType() {
        return ListContactsAction.class;
    }

    public ListContactsResult execute(ListContactsAction a, ExecutionContext ec) throws DispatchException {
        // some code using SqlSessionFactory and returning ListContactResult
        // with list of contacts
    }

    public void rollback(ListContactsAction a, ListContactsResult r, ExecutionContext ec) throws DispatchException {
        /* get action - no rollback needed */
    }

}

In a previous version of my application, which used the rpc service instead of the command template, I had a method that provided SqlSessionFactoryinjections, something like this:

@Provides
    public SqlSessionFactory getSqlSessionFactory(){
        // some code here
    }

I read about the start of gwt submission that I should provide a binding between my action and the handler, which should look something like this:

public class ContactModule extends ActionHandlerModule{
    @Override
    protected void configureHandlers() {
        bindHandler(ListContactsAction.class, ListContactsHandler.class);
    }
}

But I have a problem connecting everything with Guice, because this example is from the gwt-dispatch website:

public class DispatchServletModule extends ServletModule {
    @Override
    public void configureServlets() {
        serve( "/path/to/dispatch" ).with( DispatchServiceServlet.class );
    }
}

does not work because there is no package DispatchServiceServlet.

:

  • DispatchServletModule ( , )
  • web.xml , , GIN DispatcherAsync
  • SqlSessionFactory ( ), SqlSessionFactory, ?
  • , .

, , . - , .

0
3

GuiceServletConfig? Dispatch, Guice.

plubic class GuiceServletConfig extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new HandlerModule(), new DispatchServletModule());
    }
}

HandlerModule - ActionHandler, ContactModule.

SqlSessionFactory ContactModule, ServerModule, . .

+1

GWT-Platform gwt-dispatch rpc. , , , , Guice. .

+1

-, . . . , - .

QU: DispatchServletModule ( , )?

GuiceStandardDispatchServlet net.customware.gwt.dispatch.server.guice; . 100 , , , , GWT, '/dispatch'. , .

public class MyServletModule extends ServletModule {
  @Override protected void configureServlets() {
    serve("/com.my.module.name/dispatch")
      .with(GuiceStandardDispatchServlet.class);
  }
}

QU: web.xml , , GIN DispatcherAsync?

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>com.myapp.whatever.MyContextListener</listener-class>
  </listener>
  ...
</web-app>

... , Guice . , ContactModule, .

public class MyContextListener extends GuiceServletContextListener {
  @Override protected Injector getInjector() {
    return Guice.createInjector(new MyServletModule(), 
      new ContactModule(), new SQLStuffModule());
  }
}

QU: SqlSessionFactory ( ), SqlSessionFactory, ?

, SQLStuffModule ; SqlSessionFactory. , , , .

QU: , ?

. MyContextListener .

:

@GinModules(StandardDispatchModule.class, MyClientModule.class)
public interface MyGinjector extends Ginjector {
  MyWidgetMainPanel getMainPanel();
}

... MVP Gin . , mvp4g, , .

public class MyClientModule extends AbstractGinModule {
  @Override protected void configure() {
    bind(...).to(...);
    ...
  }
}
+1
source

Source: https://habr.com/ru/post/1744063/


All Articles