Je suis en train d'écrire une application GWT (+ GXT) en utilisant Guice / Gin pour gérer l'injection de dépendances.

côté client
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
@GinModules({ WidgetModule.class })
public interface PartmidiGinInjector extends Ginjector {
 
 
	public EventBus getEventBus();
 
 
	public VerticalPanel getMainPanel();
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
public class WidgetModule extends AbstractGinModule {
 
	@Override
	protected void configure() {
	    bind(EventBus.class).to(SimpleEventBus.class).asEagerSingleton();
 
	    bind(FichierServiceAsync.class).toProvider(FichierServiceProvider.class).asEagerSingleton();
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
public class FichierServiceProvider implements Provider<FichierServiceAsync> {
 
	private FichierServiceAsync service = null;
 
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.inject.Provider#get()
	 */
	@Override
	public FichierServiceAsync get() {
 
		if (null == service) {
			final FichierServiceAsync fichierService = (FichierServiceAsync) GWT.create(FichierService.class);
 
			((ServiceDefTarget) fichierService).setServiceEntryPoint(GWT.getModuleBaseURL() + "fichier");
 
			service = fichierService;
		}
 
		return service;
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
@RemoteServiceRelativePath("fichier")
public interface FichierService extends RemoteService {
 
	ArrayList<Fichier> getFichierListe(String code) throws PartmidiException;
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
public interface FichierServiceAsync {
 
	void getFichierListe(String code, AsyncCallback<ArrayList<Fichier>> callback);
 
}

côté server
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
public class GuiceEntryPoint extends GuiceServletContextListener {
 
	protected Injector getInjector() {
		return Guice.createInjector(
				// register the service binder.
				new ServicesBinder(),
				// register the url mapping
				new ServletMapping()
		);
	}
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
public class ServicesBinder extends AbstractModule {
 
	/*
	 * (non-Javadoc)
	 * @see com.google.inject.AbstractModule#configure()
	 */
	protected void configure() {
 
		// Binding des services
		bind(FichierService.class).to(FichierServiceServlet.class).in(Scopes.SINGLETON);
	}
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
public class ServletMapping extends ServletModule {
 
	protected void configureServlets() {
 
		serve(Constantes.UrlFichier).with(FichierServiceServlet.class);
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
@SuppressWarnings("serial")
@Singleton
public class FichierServiceServlet extends RemoteServiceServlet implements FichierService {
 
	/**
         * {@inheritDoc}
         */
	@Override
	public ArrayList<Fichier> getFichierListe(String code) throws PartmidiException {
 
		return FichierDAO.getListe(code);
	}

mon web xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
 
	<filter>
		<filter-name>guiceFilter</filter-name>
		<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>guiceFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<listener>
		<listener-class>fr.pmo.gwt.partmidi.server.injection.GuiceEntryPoint</listener-class>
	</listener>
 
	<!-- Default page to serve -->
	<welcome-file-list>
		<welcome-file>Partmidi.html</welcome-file>
	</welcome-file-list>
 
</web-app>

Partmidi.gwt.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='partmidi'>
	<!-- Inherit the core Web Toolkit stuff. -->
	<inherits name='com.google.gwt.user.User' />
	<inherits name="com.google.gwt.i18n.I18N" />
 
	<!-- Inherit the default GWT style sheet. You can change -->
	<!-- the theme of your GWT application by uncommenting -->
	<!-- any one of the following lines. -->
	<inherits name='com.google.gwt.user.theme.standard.Standard' />
	<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
	<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
 
    <!-- GXT -->
	<inherits name='com.extjs.gxt.ui.GXT' />
 
	<!-- Ginjection -->
	<inherits name='com.google.gwt.inject.Inject' />
 
	<!-- Specify the app entry point class. -->
	<entry-point class='fr.pmo.gwt.partmidi.client.Partmidi' />
 
	<!-- Specify the paths for translatable code -->
	<source path='client' />
	<source path='shared' />
 
	<extend-property name="locale" values="fr" />
	<extend-property name="locale" values="en" />
	<set-property-fallback name="locale" value="fr" />
 
</module>
mon entry point
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
public class Partmidi implements EntryPoint {
 
 
	/* le panel principal */	
	static RootLayoutPanel rlp;
 
 
	/**
         * This is the entry point method.
         */
	public void onModuleLoad() {
 
		PartmidiGinInjector ginjector = GWT.create(PartmidiGinInjector.class);
 
		// Démarrage
		Panel mainPanel = ginjector.getMainPanel();
		mainPanel.setWidth("100%");
		mainPanel.setHeight("100%");
		((HasHorizontalAlignment) mainPanel).setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		((HasVerticalAlignment) mainPanel).setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
 
		mainPanel.add(new MenuPanel(null));
 
		rlp = RootLayoutPanel.get();
	}

ma vue (extrait)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
public class FichierView extends VerticalPanel {
 
@Inject
private Provider<FichierServiceAsync> fichierServiceProvider;
 
public FichierView(final MorceauPanel parentPanel) {
 
	PartmidiCallback<ArrayList<Fichier>> callback = new PartmidiCallback<ArrayList<Fichier>>() {
 
		@Override
 		public void traiterReponse(ArrayList<Fichier> reponse) {
 
			List<FichierModel> listeFichier = new ArrayList<FichierModel>();
 
			Iterator<Fichier> it = reponse.iterator();
			while (it.hasNext()) {
				Fichier fichier = it.next();
				FichierModel model = new FichierModel(fichier);
 
				listeFichier.add(model);
			}
 
			storeFichier.add(listeFichier);
		}
	};
 
	fichierServiceProvider.get().getFichierListe(code, callback);
}
Et enfin mon problème : à l'ouverture de ma vue fichierServiceProvider est systématiquement à NULL.

Merci d'avance à ceux qui s'intéresseront à mon problème.