My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
CommandService  
CommandService overview
Updated Dec 30, 2010 by gal.dol...@gmail.com

Introduction

The command service is the way to communicate to the server.

In the server side Guit uses guice-servlet.

Choice

You can disable the CommandService if you don't want to use it or if you really don't use it (if your application do not have any action and is using the command, the execution will fail). But by default it is enabled.

To disable it, add in your gwt.xml module:

<set-configuration-property name="app.use.command" value="false">
</set-configuration-property>

Configuration

In your web.xml:

         <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.google.gwt.sample.contacts.server.MyGuiceContextListener</listener-class>
	</listener>

Declare your GuiceContextListener:

public class MyGuiceContextListener extends GuiceServletContextListener {

    public static Injector injector;

    @Override
    protected Injector getInjector() {
        return injector = Guice.createInjector(new MyServletModule());
    }
}

And declare your guice module:

public class MyServletModule extends ServletModule {

    @Override
    protected void configureServlets() {
 
        // Here use /{yourmodulename}/service
        serve("/contacts/service").with(GuiceGwtServlet.class);

        // Important!
        install(new GuitModule());
        
        // All your other bindings..
        bind(DataUtil.class).in(Singleton.class);
    }
}

Batching

Guit will automatically batch requests with 50ms of delay.

GwtService: command pattern + service as interface

The new generation utilities makes easier than ever to make server services for your gwt application.

How it works:

  • Define an interface in the server
  • Make an implementation of the interface and bind it on your guice module
  • Annotate the interface with @GuitService

Thats it!

Now guit-gen generated all the necessary code to communicate your client and your server.

example:

@GuitService
public interface MyService {

    boolean isLogged();

    void login(String user, String password);
}

This interface generates the following classes: IsLoggedAction, IsLoggedResponse, IsLoggedHandler, LoginAction, LoginResponse, LoginHandler.

The generated actions have a convenient methods to make a call:

IsLoggedAction.create().execute(new AbstractAsyncCallback<IsLoggedResponse>() {
      public void success(IsLoggedResponse response) {
               boolean logged = response.getResult();
               .....
      }
});

LoginAction.create().user("333").password("333").execute(new AbstractAsyncCallback<LoginResponse>() {
      public void success(LoginResponse response) {
              ....
      }
});

Caching

Guit 1.5 supports client side caching. The generated actions already implement hashCode() and equal() given their fields, so the only thing you need to do to use client-side caching is annotate the interface method with @Cache.

Logging

All the generated actions also implement toString(), and as guit 1.5 use java logging to log all commands you'll get a pretty print of all actions and responses.

Cross-site rpc! oh yeah!

Add cross-site support to your app with 1 line of xml code!

<inherits name="com.guit.XsRpc">
</inherits>

Remember to add the xs liker also!

<add-linker name="xs">
</add-linker>

GwtGuiceServlet

This new servlet is highly optimized for guit specifics. Do not use for non-guit apps.

Powered by Google Project Hosting