ItMill + Guice 2.0

Hi everybody,
first of all I want to say that ItMill is just awesome. In my opinion, it deserves much more attention in the Java web community than it currently has.

I started to work with Google Guice (http://code.google.com/p/google-guice/) long time ago and it strikingly increases productivity. For those who dont know Guice, its a dependency injection framework in pure java. The upcoming 2.0 even comes along with a neat servlet package that allows the configuration of filters, mappings, and parameters, and also contains some very useful scopes (RequestScope, SessionScope). See: http://code.google.com/p/google-guice/wiki/Servlets

Unfortunately, you only have to change the ApplicationServlet slightly to allow an easy subclassing of it to integrate Guice (currenlty im building my own jar for each release). In fact, only the construction of the Application instance has to be overridden (Guice will use a Provider to construct new Application instances instead of “newInstance”). See the following patch:

--------- PATCH BEGIN -------------
Index: src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

— src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java (revision 6985)
+++ src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java (working copy)
@@ -1498,8 +1498,7 @@

     // Creates new application and start it
     try {
  •        final Application application = (Application) applicationClass
    
  •                .newInstance();
    
  •        final Application application = getNewApplicationInstance(context, request, response);
           context.addApplication(application);
    
           // Sets initial locale from the request
    

@@ -1516,6 +1515,25 @@
throw e;
}
}
+

  • /**

    • Constructs a new application instance.
    • @param context
    •        the context
      
    • @param request
    •        the request
      
    • @param response
    •        the response
      
    • @return an instance of the current application
    • @throws InstantiationException
    • @throws IllegalAccessException
  • */

  • protected Application getNewApplicationInstance(WebApplicationContext context, HttpServletRequest request,

  •   	HttpServletResponse response) throws InstantiationException, IllegalAccessException {
    
  •   final Application application = (Application) applicationClass.newInstance();
    
  •   return application;
    
  • }

    /**

    • Ends the application.

--------- PATCH END -------------

Is it possible to change that in some next release?

bye
Martin

Hi Martin !

How is guice 2 is stable for now, especially the web extension ? I see it is still in prerelease state but having some plans for it to use with our application for dynamic servlet registrations.

Best,
Dmitri

Hi Dmitri,
i can recommend you the current snapshot (guice-snapshot20090205.zip) including the web extensions without any doubt. I think the term “snapshot” is rather confusing, it should be “release candidate” since it will be released with only tiny changes in the near future.

Regarding the 1.0 version, it has been around now for two years without any necessary bugfix release. Thats quite impressive and a sign of high quality.

Regards,
Martin

Does this patch has a chance to be included in version 6.0? I hope so.

Hi everyone,

Just a quick note: always create a proper ticket in
dev.itmill.com
about any enhancement or defect that you need fixed, and include any possible patches in that ticket as attachments. The development team might not catch all issues from the forum, since Trac is the main tool for them to keep above the workload.

So if anyone needs this particular issue with Guice fixed for 6.0 (or heck, maybe even 5.4), the proper place to announce it is here: http://dev.itmill.com/newticket

-Jouni

ps. you’ll need to
register
in order to post new tickets.

Thanks for the consideration of this issue. Now its a pleasure to use Guice and Vaadin together.

As a little thank you, I wrote a short article in your wiki about the integration of Guice 2.0 and Vaadin:

http://dev.vaadin.com/wiki/Articles/GuiceIntegration

I hope this might help some people, though its really very simple now.

Regards,
Martin

Awesome, thanks Martin!
I’m going to have to try that out now :slight_smile:

Best Regards,
Marc