Recevoir plusieurs paramétre inconnu dans le contrôleur spring MVC + themleaf
Bonjour, je vous remercie pour tout les effort fournis dans ce forum parce que on apprend beaucoup avec vous.
Voila mon problème j'ai une vue thyemeleaf qui m'envoie plusieurs paramètre inconnue normalement elle devra m'envoyé un champs checkbox qui contient l'id et un champs input qui contient un champs de l'entité à ajouter et ils peuvent être plusieurs selon ce qu'a coché l'uitlisateur final
voila son code Vue.html:
Code:
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
| <form th:action="@{/ajouterMembres}" th:method="POST" class="form-horizontal form-label-left">
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Nom Complet</th>
<th>Date d'ajout</th>
<th>Telephone</th>
<th>Email</th>
<th>Selectionner</th>
<th>Fonction</th>
</tr>
</thead>
<tbody>
<tr th:each="u, stat :${membreClub}">
<td th:text="${u.nomComplet}"></td>
<td th:text="${u.dateDajout}"></td>
<td th:text="${u.telephone}"></td>
<td th:text="${u.email}"></td>
<td>
<input class="custom-control-input" onclick="check(this.id);" th:id="${u.idUtilsateur}" th:name="checkbox+${u.idUtilsateur}" th:value="${u.idUtilsateur}" type="checkbox" />
</td>
<td>
<input th:name="fonction+${u.idUtilsateur}" th:id="fonction+${u.idUtilsateur}" class="form-control col-md-7 col-xs-12" disabled="disabled" name="name" required="required" type="text"/>
</td>
</tr>
</tbody>
</table>
<div class="col-md-6 col-md-offset3">
<input type="hidden" name="nomClub" th:value="${nomClub}" class="form-control col-md-7 col-xs-12"/>
<button type="submit" class="btn btn-danger">Valider</button>
</div>
</form> |
plus un script javascript qui me permet d'activer l'input une fois le checbox cocher
Code:
1 2 3 4 5 6 7 8 9 10
| script type="text/javascript">
function check(id) {
var idtext="fonction"+id;
if(document.getElementById(id).checked)
document.getElementById(idtext).disabled=false;
else
document.getElementById(idtext).disabled=true;
}
</script> |
Et voila en dernier lieux la methode dans le controleur Spring mvc:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @RequestMapping(value="/ajouterMembres",method=RequestMethod.POST)
public String ajouterMembre(String checkbox[],String fonction[],String nomClub) throws ParseException{
Bureau bureau = clubMetier.findBureauClub(nomClub);
int i=0;
for(String id: checkbox)
{ Long idU=Long.parseLong(id);
Utilisateur u= utilisateurMetier.findOne(idU);
membreBureauRepository.save(new MembreBureau(fonction[i], bureau, u));
i++;
}
return "redirect:/Club?nomClub="+nomClub;
} |
le problème c'est que je ne connais pas les paramètres que je vais recevoir j'ai sangé pour cette solution: checkbox[],String fonction[] mais ca me
Citation:
donne une exception java.lang.NullPointerException: null
Merci d'avance pour vos réponse.
Recevoir plusieurs paramétre inconnu dans le contrôleur spring MVC + themleaf
Merci Beaucoup andry pour votre j'ai essayé ::).
mais malheureusement ca me donne toujours cette exception.
2017-02-28 14:03:11.276 INFO 7416 --- [ restartedMain] ma.fs.SiteAssociationApplication : Started SiteAssociationApplication in 17.751 seconds (JVM running for 18.293)
2017-02-28 14:04:15.648 INFO 7416 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-02-28 14:04:15.649 INFO 7416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-02-28 14:04:15.709 INFO 7416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 60 ms
2017-02-28 14:04:25.422 ERROR 7416 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at ma.fs.web.ClubControler.ajouterMembre(ClubControler.java:169) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_25]
si il'y a d'autre solution svp.
Merci encore une fois.