Bonjour,
J'ai créé mon application JEE avec Spring, Struts II et Hibernate sur un autre ordinateur qui tournait sous windows avec XAMPP et MySQL.
Maintenant, je suis sous Linx Mint qui utilise LAMPP et MariaDB.
La persistence de l'objet Client fonctionnait bien avec MySQL mais maintenant que je suis avec MariaDB, je rencontre un problème lors de certaines persistences.
Pour l'instant, au stade d'avancement de mon appli, je persiste l'objet Client.
Mon appli charge bien la liste de tous les clients que j'ai créés en base de donnée mais il m'est impossible de créer ou de modifier des clients existants alors que cela fonctionnait sous MySQL.
Voici la console d'Eclipse lorsque je lance mon appli.
Je vois que le driver de MariaDB est bien pris en compte, et que toutes les tables sont reconnues par Hibernate.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 juil. 17, 2016 12:06:14 AM org.apache.catalina.startup.Catalina load INFOS: Initialization processed in 774 ms juil. 17, 2016 12:06:14 AM org.apache.catalina.core.StandardService startInternal INFOS: Démarrage du service Catalina juil. 17, 2016 12:06:14 AM org.apache.catalina.core.StandardEngine startInternal INFOS: Starting Servlet Engine: Apache Tomcat/8.0.36 juil. 17, 2016 12:06:17 AM org.apache.jasper.servlet.TldScanner scanJars INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. juil. 17, 2016 12:06:17 AM org.apache.catalina.core.ApplicationContext log INFOS: No Spring WebApplicationInitializer types detected on classpath juil. 17, 2016 12:06:17 AM org.apache.catalina.core.ApplicationContext log INFOS: Initializing Spring root WebApplicationContext juil. 17, 2016 12:06:17 AM org.springframework.web.context.ContextLoader initWebApplicationContext INFOS: Root WebApplicationContext: initialization started juil. 17, 2016 12:06:17 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFOS: Refreshing Root WebApplicationContext: startup date [Sun Jul 17 00:06:17 CEST 2016]; root of context hierarchy juil. 17, 2016 12:06:18 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFOS: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml] juil. 17, 2016 12:06:18 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName INFOS: Loaded JDBC driver: org.mariadb.jdbc.Driver juil. 17, 2016 12:06:18 AM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory INFOS: Building JPA container EntityManagerFactory for persistence unit 'mainunit' juil. 17, 2016 12:06:18 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [ name: mainunit ...] juil. 17, 2016 12:06:18 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.3.10.Final} juil. 17, 2016 12:06:18 AM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found juil. 17, 2016 12:06:18 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist juil. 17, 2016 12:06:19 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} juil. 17, 2016 12:06:19 AM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect juil. 17, 2016 12:06:19 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.Client juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [prenom, typevoie, numerovoie, codepostal, email, nomvoie, ville, idclient, nom] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.Commande juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [datecommande, isvalidated, idclient, prixtotal, idcommande] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [fk_irmwnt7a01qv9xhsuxvc7v16j] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary, fk_irmwnt7a01qv9xhsuxvc7v16j] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.Conditionnement juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [id, quantite, designation] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.Erreurs juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [message, clé, iderreur] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.LigneCommande juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [prixligne, quantite, idproduitconditionne, idlignecommande, idcommande] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [fk_12fj6vhr17hdyh37ak9k97tcd, fk_dn3202hw9gg6oty8rc2gtjv1n] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary, fk_12fj6vhr17hdyh37ak9k97tcd, fk_dn3202hw9gg6oty8rc2gtjv1n] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.Produit juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [id, stock, prix, designation] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: base_commandes.ProduitConditionne juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [prixprodcond, idconditionnement, designation, idproduitconditionne, idproduit, encarte] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [fk_bceqi96945e0tn7dvol7drfqv, fk_50etk0c4dvqc867gkqfpi2w87] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [fk_bceqi96945e0tn7dvol7drfqv, primary, fk_50etk0c4dvqc867gkqfpi2w87] juil. 17, 2016 12:06:20 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete 2016-07-17 00:06:20,301 INFO [localhost-startStop-1] dao.GenericDAO (GenericDAO.java:23) - Création GenericDAO 2016-07-17 00:06:20,343 INFO [localhost-startStop-1] dao.GenericDAO (GenericDAO.java:23) - Création GenericDAO
Mais lorsque je créée un Client, il n'y a pas de persistence et d'ailleurs, je vois dans la console sur Eclipse que le service Save normalement appelé depuis ClientsAction.java n'est même pas appelé :
Mais je ne comprends pas trop d'où cela peut-il venir !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 2016-07-17 00:06:22,782 INFO [http-nio-8080-exec-2] actions.IndexAction (IndexAction.java:14) - Appel de index 2016-07-17 00:06:22,874 INFO [http-nio-8080-exec-3] actions.IndexAction (IndexAction.java:14) - Appel de index 2016-07-17 00:08:21,531 INFO [http-nio-8080-exec-5] actions.IndexAction (IndexAction.java:14) - Appel de index 2016-07-17 00:08:21,942 INFO [http-nio-8080-exec-6] actions.ClientsAction (ClientsAction.java:65) - ClientsAction - répertoire client 2016-07-17 00:08:21,968 INFO [http-nio-8080-exec-6] dao.GenericDAO (GenericDAO.java:30) - GenericDAO : findAll - from Client Hibernate: select client0_.idClient as idClient1_0_, client0_.codePostal as codePost2_0_, client0_.nomVoie as nomVoie3_0_, client0_.numeroVoie as numeroVo4_0_, client0_.typeVoie as typeVoie5_0_, client0_.ville as ville6_0_, client0_.email as email7_0_, client0_.nom as nom8_0_, client0_.prenom as prenom9_0_ from Client client0_
Je joins, mon ClientsAction.java
le fichier struts.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 package com.chezyen.commandes.actions; import java.util.List; import java.util.Set; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.chezyen.commandes.commons.Erreurs; import com.chezyen.commandes.dao.IClientDAO; import com.chezyen.commandes.metier.Adresse; import com.chezyen.commandes.metier.Client; import com.chezyen.commandes.metier.Commande; import com.opensymphony.xwork2.ActionSupport; public class ClientsAction extends ActionSupport { private static final long serialVersionUID = 1L; private static Logger log = LogManager.getLogger(ClientsAction.class); private IClientDAO clientDAO; public void setClientDAO(IClientDAO clientDAO) {this.clientDAO = clientDAO;} public IClientDAO getClientDAO() {return clientDAO;} private int clientID; private String clientNom; private String clientPrenom; private String clientEmail; private int clientCodePostal; private String clientNomVoie; private String clientTypeVoie; private String clientNumeroVoie; private String clientVille; private Set<Commande> commandes; public int getClientID() {return clientID;} public void setClientID(int clientID) {this.clientID = clientID;} public String getClientNom() {return clientNom;} public void setClientNom(String clientNom) {this.clientNom = clientNom;} public String getClientPrenom() {return clientPrenom;} public void setClientPrenom(String clientPrenom) {this.clientPrenom = clientPrenom;} public String getClientEmail() {return clientEmail;} public void setClientEmail(String clientEmail) {this.clientEmail = clientEmail;} public int getClientCodePostal() {return clientCodePostal;} public void setClientCodePostal(int clientCodePostal) {this.clientCodePostal = clientCodePostal;} public String getClientNomVoie() {return clientNomVoie;} public void setClientNomVoie(String clientNomVoie) {this.clientNomVoie = clientNomVoie;} public String getClientTypeVoie() {return clientTypeVoie;} public void setClientTypeVoie(String clientTypeVoie) {this.clientTypeVoie = clientTypeVoie;} public String getClientNumeroVoie() {return clientNumeroVoie;} public void setClientNumeroVoie(String clientNumeroVoie) {this.clientNumeroVoie = clientNumeroVoie;} public String getClientVille() {return clientVille;} public void setClientVille(String clientVille) {this.clientVille = clientVille;} public Set<Commande> getCommandes() {return commandes;} public void setCommandes(Set<Commande> commandes) {this.commandes = commandes;} private Client client; public Client getClient() {return client;} private List<Client> clients; public List<Client> getClients() {return clients;} public String repertoire() { log.info("ClientsAction - répertoire client"); this.clients = clientDAO.findAll(); return SUCCESS; } public String nouveauClient() { log.info("nouveauClient - nom : " + getClientNom()); Adresse adresse = new Adresse(getClientNomVoie(), getClientTypeVoie(), getClientNumeroVoie(), getClientCodePostal(), getClientVille()); log.info("numero adresse : " + getClientNumeroVoie() + ", " + getClientTypeVoie() + " " + getClientNomVoie() + " " + getClientCodePostal() + " " + getClientVille()); Client client = new Client(getClientNom(), getClientPrenom(), getClientEmail(), adresse, null); if(verificationNouveauClient(adresse, client)){ log.info("vérification OK"); this.client = getClientDAO().save(client); return SUCCESS; } else { Erreurs err = new Erreurs("NewCliErr", "erreur nouveau client"); return ERROR; } } private boolean verificationNouveauClient(Adresse adresse, Client client) { this.clients = clientDAO.findAll(); for(Client cl : clients) { if(adresse.getNomVoie().equals(cl.getAdresse().getNomVoie())){ log.info("Nom de voie identique trouvé. Nom : " + adresse.getNomVoie()); return false; } } return true; } public String suppression() { log.info("ClientsAction - suppression - clientID : " + getClientID()); this.client = clientDAO.findByID(getClientID()); log.info("ClientsAction - suppression - client nom : " + this.client.getNom()); return SUCCESS; } public String valider_suppression(){ log.info("ClientsAction - suppression - clientID : " + getClientID() + ", nom : " + getClientNom()); Client client = new Client(); client = getClientDAO().remove(getClientID()); this.clients = clientDAO.findAll(); return SUCCESS; } public String modification() { log.info("ClientsAction - modification - clientID : " + getClientID()); this.client = clientDAO.findByID(getClientID()); log.info("ClientsAction - modification - client nom : " + this.client.getNom()); return SUCCESS; } public String valider_modification() { log.info("ClientsAction - valider_modification"); Client client = new Client(); log.info("ClientsAction - valider_modification - client id : " + client.getIdClient() + "attr clientID : " + getClientID()); client = client.setClient(getClientID(), getClientNom(), getClientPrenom(), getClientEmail(), getClientNomVoie(), getClientTypeVoie(), getClientNumeroVoie(), getClientCodePostal(), getClientVille()); log.info("ClientsAction - valider_modification - nomVoie : " + getClientNomVoie() + "id client : " + client.getIdClient()); this.client = clientDAO.save(client); log.info("ClientsAction - save modified client - nom : " + this.clientNom + ", id : " + getClientID()); this.clients = clientDAO.findAll(); return SUCCESS; } }
la partie du fichier gestionClients.html qui me sert à saisir les données du nouveau client et à envoyer vers le fichier gestionClients.js :
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="true"/> <constant name="struts.action.extension" value=","/> <constant name="struts.enable.SlashesInActionNames" value="true" /> <package name="default" namespace="/" extends="json-default"> <default-action-ref name="index"/> <action name="index" class="com.chezyen.commandes.actions.IndexAction" method="index" > <result name="success">/index.jsp</result> </action> <!-- Gestion des commandes --> <action name="gestComm/produits" class="com.chezyen.commandes.actions.ProduitsAction" method="gestionCommandes"> <result name="success" type="json"> <param name="includeProperties"> ^produits\[\d\]\.id$, ^produits\[\d\]\.designation$, ^produits\[\d\]\.prix$, ^produits\[\d\]\.stock </param> </result> </action> <action name="gestComm/produitSave" class="com.chezyen.commandes.actions.IndexAction" method="save"> <interceptor-ref name="defaultStack" /> <interceptor-ref name="json" /> <result name="success" type="json"> <param name="includeProperties"> ^produit\.id$, ^produit\.designation$, ^produit\.prix$, ^produit\.stock$ </param> </result> </action> <!-- gestion des clients --> <action name="gestClients/nouveau" class="com.chezyen.commandes.actions.ClientsAction" method="nouveauClient"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="json"/> <result name="success" type="json"> <param name="includeProperties"> ^client\.idClient$, ^client\.nom$, ^client\.prenom$, ^client\.adresse\.numeroVoie$, ^client\.adresse\.typeVoie$, ^client\.adresse\.nomVoie$, ^client\.adresse\.codePostal$, ^client\.adresse\.ville$ </param> </result> <result name="error" type="json"> <param name="includeProperties"> ^erreurs\.message$ </param> </result> </action> <action name="gestClients/repertoire" class="com.chezyen.commandes.actions.ClientsAction" method="repertoire"> <result name="success" type="json"> <param name="includeProperties"> ^clients\[\d\]\.idClient$, ^clients\[\d\]\.nom$, ^clients\[\d\]\.prenom$, ^clients\[\d\]\.adresse\.codePostal$, ^clients\[\d\]\.adresse\.ville$, ^clients\[\d\]\.adresse\.numeroVoie$, ^clients\[\d\]\.adresse\.typeVoie$, ^clients\[\d\]\.adresse\.nomVoie$ </param> </result> </action> <action name="gestClients/supprimer" class="com.chezyen.commandes.actions.ClientsAction" method="suppression"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="json"/> <result name="success" type="json"> <param name="includeProperties"> ^client\.idClient$, ^client\.nom$, ^client\.prenom$, ^client\.adresse\.numeroVoie$, ^client\.adresse\.typeVoie$, ^client\.adresse\.nomVoie$, ^client\.adresse\.codePostal$, ^client\.adresse\.ville$ </param> </result> </action> <action name="gestClients/valider_suppression" class="com.chezyen.commandes.actions.ClientsAction" method="valider_suppression"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="json"/> <result name="success" type="json"> <param name="includeProperties"> ^clients\[\d\]\.idClient$, ^clients\[\d\]\.nom$, ^clients\[\d\]\.prenom$, ^clients\[\d\]\.adresse\.codePostal$, ^clients\[\d\]\.adresse\.ville$, ^clients\[\d\]\.adresse\.numeroVoie$, ^clients\[\d\]\.adresse\.typeVoie$, ^clients\[\d\]\.adresse\.nomVoie$ </param> </result> </action> <action name="gestClients/modifier" class="com.chezyen.commandes.actions.ClientsAction" method="modification"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="json"/> <result name="success" type="json"> <param name="includeProperties"> ^client\.idClient$, ^client\.nom$, ^client\.prenom$, ^client\.adresse\.numeroVoie$, ^client\.adresse\.typeVoie$, ^client\.adresse\.nomVoie$, ^client\.adresse\.codePostal$, ^client\.adresse\.ville$ </param> </result> </action> <action name="gestClients/valider_modification" class="com.chezyen.commandes.actions.ClientsAction" method="valider_modification"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="json"/> <result name="success" type="json"> <param name="includeProperties"> ^clients\[\d\]\.idClient$, ^clients\[\d\]\.nom$, ^clients\[\d\]\.prenom$, ^clients\[\d\]\.adresse\.codePostal$, ^clients\[\d\]\.adresse\.ville$, ^clients\[\d\]\.adresse\.numeroVoie$, ^clients\[\d\]\.adresse\.typeVoie$, ^clients\[\d\]\.adresse\.nomVoie$ </param> </result> </action> </package> <!-- Add addition packages and configuration here. --> </struts>
Le fichier getion_client.js :
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 <div class="container" ng-controller="clientCtrl"> <div id="firstRow" class="row"> <div class="col-sm-12" style="padding-right:30px;"> <div id="nouveauClient" style="text-align:center;"> Créer un nouveau client </div> <div id="panelNouveauClient"> <div class="encadre" style="height:130px; min-width: 600px;"> <div style="text-align:center;"> <label style="color:#c7b988;">Identité</label><br /> </div> <div> <div id="tablesInlineBlock" style="width:49%;"> <div id="tablesBlock"> <label>Nom</label> </div> <div id="tablesBlock" style="min-width: 270px;"> <input id="nouveauClientNom" type="text" class="form-control" ng-model="client_nom" style="width:200px;"/> </div> </div> <div id="tablesInlineBlock" style="width:50%;"> <div id="tablesBlock"> <label>Prénom</label> </div> <div id="tablesBlock" style="min-width: 250px;"> <input type="text" class="form-control" ng-model="client_prenom" style="width:200px;"/> </div> </div> </div> </div> <div class="encadre" style="min-width: 600px;"> <div style="text-align:center;"> <label style="color:#c7b988;">Adresse</label><br /> </div> <div> <div id="tablesInlineBlock" style="width:24%;"> <div id="tablesBlock"> <label>Numéro</label> </div> <div id="tablesBlock" style="min-width: 60px;"> <input id="numVoie" type="text" class="form-control" ng-model="client_numVoie" maxlength="8" style="width:110px;"/> </div> </div> <div id="tablesInlineBlock" style="width:30%;"> <div id="tablesBlock"> <label>Voie</label> </div> <div id="tablesBlock" style="min-width: 170px;"> <select id="typeVoie" class="form-control" ng-model="client_typeVoie" style="width:150px;"> <option>Impasse</option> <option>Route</option> <option selected="selected">Rue</option> <option>Autre</option> </select> </div> </div> <div id="tablesInlineBlock" style="width:45%;"> <div id="tablesBlock"> <label>Nom voie</label> </div> <div id="tablesBlock" style="min-width: 250px;"> <input id="nomVoie" type="text" class="form-control" ng-model="client_nomVoie"/> </div> </div> </div> <div> <div id="tablesInlineBlock" style="width:49%;"> <div id="tablesBlock"> <label>Code postal</label> </div> <div id="tablesBlock" style="min-width: 90px;"> <input id="codePostal" type="text" class="form-control" ng-model="client_codePostal" maxlength="5" style="width:110px;"/> </div> </div> <div id="tablesInlineBlock" style="width:50%;"> <div id="tablesBlock"> <label>Ville</label> </div> <div id="tablesBlock" style="min-width: 290px;"> <input id="ville" type="text" class="form-control" ng-model="client_ville" style="width:250px;"/> </div> </div> </div> </div> <span class="input-group-btn"> <button class="btn btn-default" ng-click="nouveau_client(client_nom, client_prenom, client_numVoie, client_typeVoie, client_nomVoie, client_codePostal, client_ville);"> Ajouter client </button> </span> </div>
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 // cette ligne crée un nouveau module angular // le tableau en deuxieme argument contient les // dépendances a injecter dans ce module var chezYenApp = angular.module("chezYenApp", []); // Création d'un controlleur "StoreCtrl" dans notre module // le scope est automatiquement injecté par angular chezYenApp.controller("clientCtrl", function($scope, $http) { $scope.clients = []; $scope.clientModif; $http.get('../gestClients/repertoire').then(function (response) { $scope.clients = response.data.clients; }); $scope.nouveau_client = function(nom, prenom, email, numVoie, typeVoie, nomVoie, codePostal, ville){ console.log("nouveauClient nom : " + nom); $http.post('../gestClients/nouveau', { "clientNom": nom, "clientPrenom": prenom, "clientEmail": email, "clientNumeroVoie": numVoie, "clientTypeVoie": typeVoie, "clientNomVoie": nomVoie, "clientCodePostal": codePostal, "clientVille": ville }).success(function(response) { $('#nouveauClientNom').attr('value', ''); $("#panelNouveauClient").slideToggle(600); //the following line must be tried //$scope.$apply(); $scope.clients.push(response.client); }).error(function(response){ $scope.erreurs.push(response.erreurs); }); }; $scope.valider_suppression = function(idClient){ console.log("valider suppression client id : " + idClient); if(idClient != null){ $http.post('../gestClients/valider_suppression', { "clientID": idClient }).then(function successCallback(response) { console.log("succes suppression client"); $scope.clients = response.data.clients; }, function errorCallback(response) { console.log("problème suppression client"); }); } else { console.log("impossible suppression -> client null"); } fermeturePopUp(); }; $scope.supprimer_client = function(idClient) { console.log("PopUpSuppression_client id : " + idClient); $http.post('../gestClients/supprimer', { "clientID":idClient }).then(function successCallbak(response){ $scope.clientSuppr = response.data.client; console.log("succes suppression client - nom : " + $scope.clientSuppr.nom); openPopUp('popUpSuppr'); return false; }, function errorCallback(response){ console.log("problème modification client"); }); } $scope.modifier_client = function(idClient) { console.log("modifier_client id : " + idClient); $http.post('../gestClients/modifier', { "clientID":idClient }).then(function successCallbak(response){ $scope.clientModif = response.data.client; console.log("succes modification client - nom : " + $scope.clientModif.nom); openPopUp('popUpModif'); return false; }, function errorCallback(response){ console.log("problème modification client"); }); } $scope.valider_modification = function(id, nom, prenom, numVoie, typeVoie, nomVoie, codePostal, ville) { console.log("gestion_clients - Valider modification - id : " + id); if(id != null){ $http.post('../gestClients/valider_modification', { "clientID": id, "clientNom": nom, "clientPrenom": prenom, "clientEmail": email, "clientNumeroVoie": numVoie, "clientTypeVoie": typeVoie, "clientNomVoie": nomVoie, "clientCodePostal": codePostal, "clientVille": ville }).success(function(response) { $scope.clients = response.clients; }).error(function(response){ $scope.erreurs.push(response.erreurs); }); } else { console.log("impossible modification -> client null"); } fermeturePopUp(); } //Fermeture de la pop-up et du fond $('a.close, #annulerModif, #annulerSuppr').on('click', function() { //Au clic sur le bouton ou sur le calque... fermeturePopUp(); return false; }); }); //Ouverture popup function openPopUp(popID){ console.log('ouverture popUp ' + popID); var largeur_fenetre = $(window).width(); if(largeur_fenetre < 1500){ var popWidth = largeur_fenetre - largeur_fenetre * 0.1; //la largeur } else { var popWidth = largeur_fenetre - largeur_fenetre * 0.3; //la largeur } //Faire apparaitre la pop-up $('#' + popID).fadeIn().css({ 'width': Number(popWidth) }); //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS var popMargTop = ($('#' + popID).height() + 80) / 2; var popMargLeft = ($('#' + popID).width() + 80) / 2; //On affecte le margin $('#' + popID).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); //Effet fade-in du fond opaque $('body').append('<div id="fade"></div>'); //Ajout du fond opaque noir //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); } function fermeturePopUp(){ console.log("fermeture pop-up"); $('#fade , .popup_block').fadeOut(function() { $('#fade, a.close').remove(); //...ils disparaissent ensemble }); }
Le fichier persistence.xml qui se trouve dans le dossier WEB-INF :
Le fichier applicationContext.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="mainunit"> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence>
le 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
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 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd" default-autowire="byName"> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="url" value="jdbc:mariadb://localhost:3306/base_commandes"/> <property name="driverClassName" value="org.mariadb.jdbc.Driver"/> <property name="username" value="root"/> <property name="password" value=""/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="MYSQL" /> <property name="showSql" value="true" /> </bean> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="produitDAO" class="com.chezyen.commandes.dao.ProduitDAO" /> <bean id="clientDAO" class="com.chezyen.commandes.dao.ClientDAO" /> </beans>
Si quelqu'un peut m'éclairer, je vous en remercie d'avance !
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 <?xml version="1.0" encoding="UTF-8"?> <web-app id="struts_blank" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Struts2 Spring4 JPA2 with Hibernate4</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <filter> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
Partager