My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads

GWT-cs is a GWT module that allows developers to construct their GWT client side code using Spring IoC. It combines the powerful features of deferred binding and generator from GWT and inverse of control from Springframework, so that developers can define their application structures not only of their server code, but also of their client side GWT class beans.

One can enjoy the full support of the existing Srpingframework tool sets, such as Spring IDE Eclipse plugin in authoring the Spring bean configurtion files. GWT compiler will invoke the GWT-cs bean factory generator to generate the factory class(s) at compile time from the (Spring) configuration file(s), which will then be compiled by GWT compiler into javascript for runtime execution.

GWT-cs features a tiny archive file with only two classes and one interface. The current release (v0.11) supports a subset of the Spring IoC functions that are enough to let developers to build their GWT application structures. GWT-cs does not dictate how it is done, but leaves the door fully open for anybody to do it in his own way. Typically, a bean defined in Spring xml configuration file would be a GWT Composite class and one can define one or more beans to collaborately build a page.

How does it work

GWT-cs integrates the Spring BeanFactory API with the GWT generator. The first thing it does is to instruct GWT compiler to invoke the GWT-cs generator to generate BeanFactory source code for any interfaces that inherate from BeanFactory interface. The GWT-cs generator which extends GWT Generator uses the Spring API to load the BeanFactory configuration file(s) and generate the source code.

With only three java files in the module, everyone should be able to see how it works, once he/she goes through the code.

I started the generator class based on a forum post by riyaz.mansoor.

How to use it

  • Download and include the GWTcs jar in your GWT project build path
  • Download and include the spring.jar in your GWT project build path
  • Inherate the org.cs.GWTcs module
  • Create an interface (named, say, MyBeanFactory) that inherates org.cs.client.generator.BeanFactory. Note it must be in a package in the your GWT client pachage branch.
  • import org.cs.client.generator.BeanFactory;
    
    public interface MyBeanFactory extends BeanFactory {
    
    }
  • Create the Spring bean configuration file, MyBeanFactory.xml, in the same package of the interface above. Define your beans and their collaboration pattern as you desire. Note that all beans in this configuration files must be GWT client classes.
  • Define at least one Composite bean as the home page class in this xml configuration
  • In somewhere in your GWT client initialization blocks, in the onModuleLoad of your EntryPoint class for example, call GWT.create() method to load the BeanFactory, get the home page bean from the factory and added it to the rootPanel. For example:
  • public void onModuleLoad() {
    BeanFactory bf = (BeanFactory) GWT.create(MyBeanFactory.class);
    		
    RootPanel rootPanel = RootPanel.get("apparea");
    
    Composite comp = (Composite) bf.getBean("homeComp");
    rootPanel.add(comp);
    }

Ths subsequent screen navigations should follow the collaboration patterns defined in the configuration.

What does it support

Not all the Spring IoC features are supported. I always follow the 80/20 rule. The current release has enough to support my own use cases.

  • Everything that is conforming to Spring's configuration xml schema will be loaded into the BeaDefinitions, since GWTcs is using Spring's API. For example, the import tag is supported.
  • All beans are constructed from their default constructors
  • GWTcs only takes notice of a few attribute values in the bean definition tag: id, class, scope. The rest of the attributes are ignored in the BeanFactory generation.
  • The singleton and proptype scope types are supported.
  • The setter injection is supported, but not the constructor injection.
  • Bean ref is supported but not the inner class.
  • Only the simple property types are supported. Collection type propertyies are ignored.
  • Any other Spring IoC features not mentioned above are not supported.

If you need something that can't be done with the current release, send me a note at yxzhao100@gmail.com.

Usuage Example

Download the example war file and its source code jar file. Drop the war in your tomcat (or else) server webapps directory, start tomcat server and point your browser to http://yourserver:yourport/GWTcsTest to see the sample application.

This example implements a Petri net like flow structure. Every screen (a GWT Composite class) connects to other screens through Transitions as defined in the Spring bean configuration xml file.

Powered by Google Project Hosting