Salut,
Je viens solliciter votre aide sur un soucis de date dans mon projet :
Voici l'erreur générée :
Voici mon controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 org.springframework.validation.BeanPropertyBindingResult: 2 errors Field error in object 'personnes' on field 'datenaissance': rejected value [2018-09-12]; codes [typeMismatch.personnes.datenaissance,typeMismatch.datenaissance,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [personnes.datenaissance,datenaissance]; arguments []; default message [datenaissance]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'datenaissance'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @org.springframework.format.annotation.DateTimeFormat @javax.persistence.Temporal java.util.Date] for value '2018-09-12'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-09-12]] Field error in object 'personnes' on field 'datenumsecurite': rejected value [2018-09-12]; codes [typeMismatch.personnes.datenumsecurite,typeMismatch.datenumsecurite,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [personnes.datenumsecurite,datenumsecurite]; arguments []; default message [datenumsecurite]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'datenumsecurite'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @org.springframework.format.annotation.DateTimeFormat @javax.persistence.Temporal java.util.Date] for value '2018-09-12'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-09-12]]
Ma vue Html
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 package bj.prexed.astrh.web; import bj.prexed.astrh.daorepository.CountryRepository; import bj.prexed.astrh.daorepository.PersonnesRepository; import bj.prexed.astrh.daorepository.SocietyRepository; import bj.prexed.astrh.entities.Country; import bj.prexed.astrh.entities.Personnes; import bj.prexed.astrh.entities.Society; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.sql.Date; import java.text.SimpleDateFormat; @Controller @RequestMapping(value = "/smartrh") public class PersonnesCtrl { @Autowired private PersonnesRepository personnesRepository; @Autowired private CountryRepository countryRepository; @Autowired private SocietyRepository societyRepository; @RequestMapping(value = "/liste.php") public String Liste(Model model, @RequestParam(name = "page",defaultValue = "0")int p, @RequestParam(name = "motCle", defaultValue = "")String mc){ Page<Personnes> personnesPage = personnesRepository.chercherParPersonne("%" + mc + "%" ,PageRequest.of(p,10)); int pagesCount = personnesPage.getTotalPages(); int[]pages = new int[pagesCount]; for(int i=0; i<pagesCount; i++)pages[i] =i; model.addAttribute("personnesPage",personnesPage); model.addAttribute("pageCourante",p); model.addAttribute("motCle",mc); return "personnelist"; } @RequestMapping(value = "/saisiepersonne.php", method = RequestMethod.GET) public String Saisie(Model model){ model.addAttribute("personnes",new Personnes()); model.addAttribute("countryNaissancelist", countryRepository.findAll()); model.addAttribute("countryOriginelist", countryRepository.findAll()); model.addAttribute("societeList", societyRepository.findAll()); return "personneCreate"; } @RequestMapping(value = "enregistrerpersonne.php", method = RequestMethod.POST) public String Save(Model model, Long idsociete, String sortOrderOri,String sortOrder,@Valid Personnes personnes, BindingResult bindingResult){ model.addAttribute("countryNaissancelist", countryRepository.findAll()); model.addAttribute("countryOriginelist", countryRepository.findAll()); model.addAttribute("societeList", societyRepository.findAll()); Country countrynais = countryRepository.getBySortOrder(sortOrder); Country countryOrigine = countryRepository.getBySortOrder(sortOrderOri); Society soc = societyRepository.getOne(idsociete); personnes.setSociete(soc); personnes.setPaysNaissance(countrynais); // personnes.setNationalite(countryOrigine); if(bindingResult.hasErrors()){ return "personneCreate"; } else { personnesRepository.save(personnes); return "redirect:liste.php"; } } @InitBinder public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true)); } }
Merci de m'aider.
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layout"> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>Création</title> </head> <body> <div layout:fragment="content"> <div class="container"> <form th:action="@{enregistrerpersonne.php}" method="post" th:object="${personnes}"> <div class="card"> <div class="card-header">Saisie</div> <div class="card-body"> <div class="row"> <div class="form-inline col-md-12"> <div class="form-inline col-md-6"> <div class="form-group"> <label for=""> Id : </label> <input type="text" th:field="${personnes.reference}" class="form-control" placeholder="reference"/> <span class="text-danger" th:errors = "${personnes.reference}"></span> </div> </div> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 71px">Société :</label> <select name="idsociete" class="form-control col"> <option th:each="p:${societeList}" th:value="${p.idsociete}" th:text="${p.raisonsocial}"></option> </select> </div> </div> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 70px">Sexe:</label> <select name="sexe" class="form-control col "> <option value="feminin">Femme</option> <option value="masculin">Homme</option> </select> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for=""> Civilite:</label> </div> <select name="civilite" class="form-control col"> <option value="Monsieur">M.</option> <option value="Madame">Mme</option> <option value="Mademoiselle">Mlle</option> </select> </div> </div> <br/> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 70px">Noms:</label> <input type="text" th:field="${personnes.nom}" class="form-control col-md-8 " placeholder="Votre Nom"/> <span class="text-danger" th:errors = "${personnes.nom}"></span> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for=""> Prenoms:</label> </div> <input type="text" th:field="${personnes.prenoms}" class="form-control col-md-8" placeholder="Prénoms"/> <span class="text-danger" th:errors = "${personnes.prenoms}"></span> </div> </div> <br> <div class="form-group"> <!--<label for="">Personne</label>--> <input type="hidden" th:field="${personnes.personne}" class="form-control" placeholder="Personne"/> </div> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 70px">Naissance:</label> <input type="date" th:field="${personnes.datenaissance}" class="form-control col-md-8 " placeholder="Votre Date"/> <span class="text-danger" th:errors = "${personnes.datenaissance}"></span> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for=""> Lieu:</label> </div> <input type="text" th:field="${personnes.lieunaissance}" class="form-control col-md-8" placeholder="Lieu de Nais"/> <span class="text-danger" th:errors = "${personnes.lieunaissance}"></span> </div> </div> <br> <!--Numero--> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 70px">Sec. Social:</label> <input type="text" th:field="${personnes.nsecuritesocial}" class="form-control col-md-8 " placeholder="Votre Numero"/> <span class="text-danger" th:errors = "${personnes.nsecuritesocial}"></span> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for=""> Date Sec. Soc.:</label> </div> <input type="date" th:field="${personnes.datenumsecurite}" class="form-control col-md-8" placeholder="date"/>--> <span class="text-danger" th:errors = "${personnes.datenumsecurite}"></span> </div> </div> <br> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 71px">Pays.Nais :</label> <select name="sortOrder" class="form-control col"> <option th:each="p:${countryNaissancelist}" th:value="${p.sortOrder}" th:text="${p.commoName}"></option> </select> <span class="text-danger" th:errors = "${personnes.paysNaissance}"></span> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for="">Origine:</label> </div> <select name="sortOrderOri" class="form-control col"> <option th:each="p:${countryOriginelist}" th:value="${p.sortOrder}" th:text="${p.commoName}"></option> </select> <span class="text-danger" th:errors = "${personnes.nationalite}"></span> </div> </div> </div> <div class="col-xs-6 col-md-6"> <div class="form-group"> <label>Situation Matrimoniale </label> <select name="situationmatrimoniale" class="form-control col "> <option value="Concubin(e)">Concubin(e)</option> <option value="Marié(e)">Marié(e)</option> <option value="Célibataire">Célibataire</option> <option value="Divorcé(e)">Divorcé(e)</option> </select> </div> <br> <div class="form-inline col-md-12"> <div class="form-inline col-md-6 "> <label for="" class="" style="width: 70px">Tel.</label> <input type="text" th:field="${personnes.telephone}" class="form-control col-md-8" placeholder="Tel"/> </div> <div class="form-inline col-md-6 "> <div style="width: 70px"> <label for="">Email:</label> </div> <input type="email" th:field="${personnes.email}" class="form-control col-md-8" placeholder="EMail"/> <span class="text-danger" th:errors = "${personnes.email}"></span> </div> </div> <br> <div class="form-group"> <!--<label>motpass : </label>--> <input type="password" th:field="${personnes.motpass}" class="form-control col" placeholder="Mot de Passe" id="pass"/> <span class="text-danger" th:errors = "${personnes.motpass}"></span> </div> <div class="form-group"> <!--<label>confirmation : </label>--> <input type="password" name="confirmation" class="form-control col" placeholder="Confirmation" id="conf"/> </div> <div class="form-group"> <!--<label>confirmation : </label>--> <input type="file" th:field="${personnes.photo}" class="form-control" placeholder="image"/> </div> <br> <div class=""> <button class="btn btn-block btn-lg btn-success" onclick="controlePass(document.getElementById('pass'),document.getElementById('conf'))" type="submit">Valider</button> </div> </div> </div> </div> </form> </div> </div> </body> </html>
Partager