Bonjour,
J'ai récemment suivi ce tuto : <html>http://fponchel.developpez.com/tutoriel/flex3/integration/blazeds-spring/</html>
et je suis parvenu jusqu'au bout. J'essaye maintenant d'appliquer cette méthode à mon appli, mais je rencontre quelques problèmes.
Mon appli cliente Flex invite l'utilisateur à rentrer des info sur un livre dans le but de l'enregistrer en ePub.
J'ai bien entendu créé mes deux types Livre et Chapitre. Dans cet exemple, le livre aura un titre, un auteur, une langue, un chapitre avec un paragraphe.
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 <mx:Script> <![CDATA[ import mx.events.FlexEvent; import mx.controls.Alert; import mx.rpc.events.ResultEvent; private function onResult(evt:ResultEvent):void { Alert.show("C'est bon !!!"); } private function onFault(evt:Event):void { Alert.show("Erreur lors de l'enregistrement !"); } private function enregistrer(evt:Event):void { var monLivre:Livre = new Livre(); var monChapitre:Chapitre = new Chapitre(); var maListePara:Array = new Array(); var maListeChap:Array = new Array(); monLivre.setTitre(titreLivre.text); monLivre.setCreateur(auteurLivre.text); monLivre.setLangue(cb.selectedItem.toString()); monChapitre.setTitre(titreChapitre.text); maListePara.push(zoneChapitre.text); monChapitre.setListeParagraphes(maListePara); maListeChap.push(monChapitre); monLivre.setListeChapitres(maListeChap); roWriteEpub.enregistrerEpub("coucou23456"); } ]]> </mx:Script> <mx:RemoteObject id="roWriteEpub" destination="writeEpubDest" result="onResult(event)" fault="onFault(event)"/> <mx:Panel width="622" layout="absolute"> <mx:Label x="212.5" y="10" text="Test de création d'un Epub simple"/> <mx:Label x="47" y="60" text="Titre : "/> <mx:TextInput id="titreLivre" x="109" y="58" width="409.75"/> <mx:Label x="36" y="90" text="Auteur : "/> <mx:TextInput id="auteurLivre" x="109" y="88" width="409.75"/> <mx:Label x="31" y="120" text="Langue : "/> <mx:ComboBox id="cb" x="109" y="118" width="77"> <mx:ArrayCollection> <mx:Object label="fr"/> <mx:Object label="en"/> <mx:Object label="es"/> </mx:ArrayCollection> </mx:ComboBox> <mx:HRule x="31" y="148" width="379"/> <mx:Label x="74" y="158" text="Titre du Chapitre : "/> <mx:TextInput id="titreChapitre" x="209" y="156" width="309.75"/> <mx:TextArea id="zoneChapitre" x="209" y="186" width="309.75" height="257"/> <mx:Label x="25" y="187" text="Contenu (un paragraphe) : "/> <mx:Button id="btnSave" x="370" y="470" label="Enregistrer" click="enregistrer(event)"/> </mx:Panel>
J'appelle ensuite la méthode enregistrerEpub, en lui passant en paramètre le Livre. J'ai bien sur pris soin d'écrire les classes Livre et Chapitre en Java.
Je rencontre alors un problème : on m'indique que :
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
36
37
38
39
40
41
42
43
44
45
46
47
48 public class SaveLivre { public void enregistrerEpub(Livre monLivre) { { System.out.println("coucou"); Publication epub = new Publication(); epub.addDCMetadata("title", monLivre.getTitre()); epub.addDCMetadata("creator", monLivre.getCreateur()); epub.addDCMetadata("language", monLivre.getLangue()); NCXResource toc = epub.getTOC(); TOCEntry rootTOCEntry = toc.getRootTOCEntry(); OPSResource main = epub.createOPSResource("OPS/main.html"); epub.addToSpine(main); OPSDocument mainDoc = main.getDocument(); ArrayList<Chapitre> listChap = new ArrayList<Chapitre>(); ArrayList<String> listPara = new ArrayList<String>(); listChap = monLivre.getListeChapitres(); listPara = listChap.get(0).getListeParagraphes(); TOCEntry mainTOCEntry = toc.createTOCEntry(listChap.get(0).getTitre(), mainDoc.getRootXRef()); rootTOCEntry.add(mainTOCEntry); Element body = mainDoc.getBody(); Element h1 = mainDoc.createElement("h1"); h1.add(listChap.get(0).getTitre()); body.add(h1); Element paragraph = mainDoc.createElement("p"); paragraph.add(listPara.get(0)); body.add(paragraph); OCFContainerWriter writer = new OCFContainerWriter( new FileOutputStream("hello.epub")); epub.serialize(writer); }catch (Exception e) { e.printStackTrace(); } } }
[BlazeDS]Error instantiating application scoped instance of type 'com.service.SaveLivre' for destination 'writeEpubDest'.
Voici mon remoting-config.xml :
J'ai essayé d'exécuter mon appli avec le moins de code possible en modifiant notamment la signature de ma méthode, en lui passant simplement une chaine de caractère et en l'affichant, un peu comme dans le tuto et devinez quoi ! Ca marche !
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 <?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf"/> </default-channels> <destination id="writeEpubDest"> <properties> <source>com.service.SaveLivre</source> <scope>application</scope> </properties> </destination> </service>
Mon problème viendrai-t-il d'un souci dans le passage de mon Livre, AS3 to Java ?
Merci.
Partager