Vaadin 7 Guice Integration

I’ve done some searching and found a few resources detailing Vaadin 7 Guice integration, but the the documents do not seem to be valid for beta4.

Specifically
this post
has quite a bit of detail but does not work with beta 4 (at least not that I can tell).

At this point, I’ve extended VaadinServlet and DefaultUIProvider and bound both of them via Guice. So far, this all makes sense. How do I go about telling Vaadin about my UIProvider?

Some of the reading I’ve found seems to indicate that I want to register a SessionInitListener with VaadService somehow. I tried doing this in the constructor of my implementation of VaadinServlet:

    
public class MyAppServlet extends VaadinServlet {
  @Inject
  MyAppServlet(){
    this.getService().addSessionInitListener(listener)
  }
}
 

but this throws an NPE.

Am I going about this correctly?
If so, where is the proper place to register the SessionInitListener?

I managed to work around this with the following code inside my class that extends VaadinServlet:


 @Override
  public VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration){
    VaadinServletService service = super.createServletService(deploymentConfiguration);
    service.addSessionInitListener(this);
    return service;
  }

This really doesn’t feel right and I’m hoping someone can point me at something better, but doing this allows me to register a SessionInitListener and then in my SessionInitListener:


  @Override
  public void sessionInit(SessionInitEvent event) throws com.vaadin.server.ServiceException {
    event.getSession().addUIProvider(this.uiProvider);
  }

Hi g g,

I’m preparing a new blog post for the upcoming beta 5 release (with a “complete” GuiceVaadinModule) - but attached my current working version for beta 4 here as well. A blog is not the best way to present a tutorial anyway. Did you see the
latest
post? Maybe, a better place is the wiki here at Vaadin - just close to
Creating a basic application
.

Cheers,
Christian
12585.zip (4.12 KB)

Hi Christian

I did read you latest post. I also agree that some place close to “Creating a bsic application” is a good place for that sort of tutorial. My impl, more or less, looks the same as yours. The only difference is that my Servlet extends VaadinServlet rather than the GAE equivalent.

Thanks for your blog btw. Without it, it would have taken me much much longer to figure this all out.

With thanks to Christian … for anyone interested in this topic, I have also created a very simple
sample app
with Vaadin 7 beta 8, Guice, and JUnit testing with Guice.