A search for meaning in software and life
RSS icon Email icon Home icon
  • GWT Plugin for Grails 0.4-SNAPSHOT

    Posted on July 23rd, 2009 Peter 18 comments

    I have just released a new interim version of the GWT plugin for Grails. The main changes are:

    • it works with GWT 1.6 properly
    • GWT client requests now go through a controller
    • new command: clean-gwt-modules

    Two of those are pretty self-explanatory, but the second one deserves a closer look.

    In the beginning…

    The traditional approach to GWT RPC involves creating a servlet that extends GWT’s RemoteServiceServlet class for each remote service in your application. Prior to version 0.4, the plugin used a technique based on that approach but geared towards Grails. Rather than requiring the user to create his own servlets and configure them in the web descriptor, the plugin set up a single servlet (extending RemoteServiceServlet) for each GWT module. The servlets simply forwarded requests to the appropriate Grails service.

    This approach worked well, particularly as the user gained all the benefits of using proper Grails services, but it meant that neither URL mappings nor Grails filters took effect. Each module had to send requests to a hard-coded URL: /gwt/<moduleName>/rpc. With the introduction of version 0.4 of the plugin, this has all changed.

    Enter GwtController

    The custom GWT servlet has gone, disappeared, vanished. In its place you’ll find a new controller: GwtController. It works in a similar way to the old servlet, but because requests now go through the standard Grails dispatch logic, URL mappings and Grails filters can now be used on GWT requests.

    You don’t have to do anything special to get the new version of the plugin working with your application because it comes with a URL mapping that matches the old hard-coded URL:

    class GwtUrlMappings {
        static mappings = {
            "/gwt/$module/rpc"(controller: "gwt", action: "index")
        }
    }
    

    Note that the above mapping includes a module parameter, but the controller currently doesn’t use it any way. It’s only there so that the mapping behaves the same as the old servlet URLs.

    If you want to send GWT requests to a different URL, simply add a new entry to your application’s URL mappings. You will need to map the URL to the same controller and action as shown in the code above.

    That’s all there is to it! Please try it out and let me know of any problems.