Navigator7 and Guice

First, thanks for the addon, John. I have only just got started with it, but it seems to be easy to use, and answer a lot of problems.

I would like to combine use of Navigator7 with Guice for dependency injection - but looking at the notes for
Guice
integration, and NavigableApplicationServlet, I am struggling to combine them; I would admit my servlet knowledge is limited, which is not helping.

Any pointers would be greatly appreciated

Hi David,

I have that working. You have to do the following steps:


1.
Extends the NavigableApplicationServlet. You have to do that because Guice need to bound servlets in Singleton scopes, so in order to set the NavigableApplicationServlet as Singleton, extend it and add the @Singleton annotation (It’s just a blank class).


@Singleton
public class NavigatorServlet extends NavigableApplicationServlet { }


2.
In your module, map the above servlet to another url pattern than “/" (as example, you can use: "/app/”). As you can see in the example below, this is needed because you have the “/*” uri patter mapped to the GuiceServlet.


	@Override
	protected void configureServlets() {
		super.configureServlets();
		
		// = Init. Parameters.
		final Map<String, String> initParams = new HashMap<String, String>();
		
		// = Configure the Servlet.
		serve("/*").with(GuiceApplicationServlet.class, initParams);
		
		final Map<String, String> navInitParams = new HashMap<String, String>();
		navInitParams.put("webApplication", "com.yoostar.application.MyWebApplication");
		navInitParams.put("application", "com.yoostar.application.MyWebApplication");
		
		serve("/app/*").with(NavigatorServlet.class, navInitParams);
		
		// = Bind our application.
                bind(Application.class).to(MyNavigableApplication.class).in(ServletScopes.SESSION);
	}


3.
Follow the initial setup of the Navigator 7.

Let me know if its work for you. I have an example if you want it.
Cheers!.
Mauro.

Hi Mauro

I missed this reply somehow - but thanks. We did get there in the end, and I would be happy to share that with anyone who reads this, although I think Mauro has already provided a good answer.

I have to say we are finding the combination of Vaadin, the Navigator7 addon and Guice a very productive one