Bonjour à tous,
Je suis debutante en Flex. J'ai créé un projet Flex/Java combined avec le Spring Blaze DS integration. Le framework Spring est bien mis en place. J'utilise le JPA pour la partie de persistence. Dans l'interface flex je veux renseigner un champ Product name et quand je clique sur un bouton "Add Product" un id pour l'entite est generé et l'entite avec le nom qui ven d'etre renseigner. J'ai un entite ProductEntity qu'est comme suite
Le productDao pour gere la partie persistence pour l'entite product
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
63
64
65
66
67
68
69 /** * */ package entities; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class ProductEntity { /** * default constructor */ public ProductEntity() { } /** * Parametized constructor * * @param productId * @param name */ public ProductEntity(String name) { this.name = name; } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer productId; @Column(length = 40) private String name; /** * @return the productId */ public Integer getProductId() { return productId; } /** * @param productId * the productId to set */ public void setProductId(Integer productId) { this.productId = productId; } /** * @return the name */ public String getName() { return name; } /** * @param name * the name to set */ public void setName(String name) { this.name = name; } }
L'interface productService
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 /** * */ package dao; import org.springframework.flex.remoting.RemotingDestination; import org.springframework.orm.jpa.support.JpaDaoSupport; import org.springframework.stereotype.Service; import service.ProductService; import entities.ProductEntity; /** * @author bbasdeo * */ @Service @RemotingDestination public class ProductDao extends JpaDaoSupport implements ProductService { /* * (non-Javadoc) * * @see service.ProductService#addProduct(entities.ProductEntity) */ @Override public void addProduct(ProductEntity product) { this.getJpaTemplate().persist(product); } }
Le panel pour saisir le nom du produit:
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 /** * */ package service; import entities.ProductEntity; /** * @author bbasdeo * */ public interface ProductService { /** * Méthode pour ajouter un nouveau produit * * @param product */ void addProduct(ProductEntity product); }
Le clickHandler et le remote tag
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <mx:Panel id="panelForm"> <mx:Label text="Product Name:" x="5" y="10"/> <mx:TextInput id="productName" x="5" y="20"/> <mx:Button id="btnAddProduct" click="addProduct()" label="Add Product"/> </mx:Panel>
Comment faire pour instancier le productEntity dans l'interface qui se trouve dans le src java et les code flex qui se trouve dans le flex_src?
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 <mx:Script> /** * Méthode invoquée en cas de succès de l'appel RPC */ private function onResult(event:ResultEvent):void { // Afficher la réponse taReponse.text=event.result as String; } /** * Méthode invoquée en cas d'échec de l'appel RPC */ private function onFault(event:FaultEvent):void { // Afficher le message d'erreur taReponse.text=event.fault.message; } private function addProduct():void { // on passe l'entité product pour sauvegarder un nouveau roProductService.addProduct } ]]> </mx:Script> <!--le remote service pour product--> <mx:RemoteObject id="roProductService" destination="productService" result="onResult(event)" fault="onFault(event)"/>
Quelqu'un aurait une idée là-dessus, svp?
J'ai mis en PJ l'arboresence de mon projet
Neerou
Partager