Bonjour.
Je rencontre un petit soucis concernant les mécanismes de serialization avec GWT.
Donc dans mon package client j'ai
- DataBindingExemple : ma classe entrypoint
- IPersonne : une interface qui doit me servir à récupérer un objet se trouvant sur le serveur.
- RemotePersonne et RemotePersonneAsync pour le service.
Dans mon package serveur :
- Personne : ma classe personne
- RemotePersonneImpl : l'implémentation de mon service.
Dans mon projet, je souhaite réutiliser mes classes métier (ici Personne) se trouvant sur le serveur dans mon interface coté client. Et pour ce projet, ces classes métier sont générées dynamiquement au démarrage de l'application puis chargées. Elles ne peuvent donc pas être connues de mon coté client lors de la compilation de GWT, mais je connais la structure de mes classes. C'est pour cela que je compte les utiliser au travers d'une interface.
Les codes coté serveur :
Personne.classRemotePersonneImpl :
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
33 package com.zenika.tutorial.gwt.server; import com.zenika.tutorial.gwt.client.IPersonne; public class Personne implements IPersonne{ private String nom; private String prenom; public Personne() { } public Personne(String prenom, String nom) { this.prenom = prenom; this.nom = nom; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } }
Coté client :
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 package com.zenika.tutorial.gwt.server; import com.zenika.tutorial.gwt.client.IPersonne; import com.zenika.tutorial.gwt.client.RemotePersonne; import com.google.gwt.user.server.rpc.RemoteServiceServlet; public class RemotePersonneImpl extends RemoteServiceServlet implements RemotePersonne { public IPersonne getPersonnes(){ IPersonne p1 = (IPersonne) new Personne(); p1.setNom("Nom"); p1.setPrenom("Prenom"); return p1; } }
Mon interface IPersonne
et ma classe DataBindingExample
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 package com.zenika.tutorial.gwt.client; import com.google.gwt.user.client.rpc.IsSerializable; public interface IPersonne extends IsSerializable{ public String getNom(); public void setNom(String nom) ; public String getPrenom(); public void setPrenom(String prenom) ; }
Au moment de la compilation du client en mode hosted j'ai cette erreur :
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
33
34
35 package com.zenika.tutorial.gwt.client; import com.extjs.gxt.ui.client.widget.MessageBox; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.ServiceDefTarget; public class DataBindingExemple implements EntryPoint { public void onModuleLoad() { final RemotePersonneAsync ihmService = ( RemotePersonneAsync )GWT.create( RemotePersonne.class ); ServiceDefTarget endpoint = ( ServiceDefTarget )ihmService; String moduleRelativeURL = GWT.getModuleBaseURL()+"/personne"; endpoint.setServiceEntryPoint( moduleRelativeURL ); final AsyncCallback callback = new AsyncCallback() { public void onSuccess( Object result ) { // take the result coming from the server IPersonne personne = (IPersonne) result; Window.alert(personne.getNom()); } public void onFailure( Throwable caught ) { MessageBox.prompt( "Error", "Error while logging in" + caught.getMessage() ); } }; ihmService.getPersonnes(callback); } }
[DEBUG] Rebinding com.zenika.tutorial.gwt.client.RemotePersonne
[DEBUG] Invoking <generate-with class='com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator'/>
[DEBUG] Generating client proxy for remote service interface 'com.zenika.tutorial.gwt.client.RemotePersonne'
[DEBUG] Analyzing 'com.zenika.tutorial.gwt.client.RemotePersonne' for serializable types
[DEBUG] Analyzing methods:
[DEBUG] public abstract com.zenika.tutorial.gwt.client.IPersonne getPersonnes()
[DEBUG] Return type: com.zenika.tutorial.gwt.client.IPersonne
[DEBUG] com.zenika.tutorial.gwt.client.IPersonne
[ERROR] Type 'com.zenika.tutorial.gwt.client.IPersonne' was not serializable and has no concrete serializable subtypes
Avez vous une idée du problème?
Partager