Hello !

J'ai très bien compris comment faire un formulaire de saisie/édition avec un seul objet java adossé au formulaire, mais j'échoue lamentablement dès que j'ai une collection d'objets à éditer dans mon formulaire.

Voici le code concret :
- formulaire.jsp
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
<!-- Formulaire de saisie -->
<form method="post">
			<strong>Cochez les produits à reprendre : </strong>
			<br />
			<br />
			<table border="0">
				<tr>
				<th>Date</th>
				<th>Produit</th>
				<th>Code</th>
				<th>Qté</th>
				</tr>
				<c:forEach var="repriseProduit" items="${reprisesProduits}">
					<tr>
					<td><dt:format pattern="dd/MM/yyyy">${repriseProduit.date.time}</dt:format></td>
					<td><c:out value="${repriseProduit.nom_produit}"/></td>
					<td><c:out value="${repriseProduit.code}"/></td>
					<td><c:out value="${repriseProduit.quantite}"/></td>
					<td><input type="checkbox" name="repriseProduit.checked" value="true"></td>
					</tr>	
				</c:forEach>
			</table>
	<input type="submit" value="Valider">
	<a href="<c:url value="/reprises_labo.html?action=list"/>">Annuler</a>
</form>
-Controleur [SimpleFormController] :
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
 
	// Prépare le formulaire à afficher
	@Override
	protected Object formBackingObject(HttpServletRequest request) throws Exception {
		// on retrouve le code du labo dans le contexte de session
		String codeLabo = ((Labo)request.getSession(false).getAttribute("infosLabo")).getCode_gross_fourn();
 
		// On recherche les produits à reprendre
		Collection reprisesProduits = servicePg.getReprisesLabo(codeLabo);
 
		// on retourne l'objet
		return reprisesProduits;
 
	}
 
 
	// binder pour la date
	@Override
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
		// création d'un format de date
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
 
		// format strict
		format.setLenient(false);
 
		// on enregistre un éditeur de propriétés String (dd/MM/yyyy) - java.util.Date
		// CustomDateEditor est fourni par Spring
		// la date pourra être vide (2ième paramètre de CustomDateEditor)
		binder.registerCustomEditor(java.util.Date.class, null, 
				new CustomDateEditor(format, true));
	}
 
 
	// exécution de la commande
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {		
 
		// On retrouve l'objet command
		Collection reprisesProduits = (Collection) command;
 
		// on archive les produits cochés
		Collection<Object> reprises = new ArrayList<Object>();
		for (Iterator iter = reprisesProduits.iterator(); iter.hasNext();) {
			RepriseProduit element = (RepriseProduit) iter.next();
			// Si coché, on l'archive
			if (element.getChecked()){
				reprises.add(element);
				System.out.println("Elément coché : " + element);
			}
		}
 
		// et on redirige vers reprises_labo
		return new ModelAndView(new RedirectView("/reprises_labo.html?action=list", true));
 
	}
 
}
-S-servlet.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
 
	<bean id="Commandes.ControllerReprisesLaboArchive" 
		class="net.baboutini.commandes.web.ControllerReprisesLaboArchive">
		<property name="sessionForm">
			<value>true</value>
		</property>
		<property name="commandName">
			<value>reprisesProduits</value>
		</property>
		<property name="formView">
			<value>reprises_labo_archive</value>
		</property>
		<property name="servicePg">
			<ref bean="servicePg"/>
		</property>
	</bean>
Quand j'affiche la page, j'ai bien ma liste de produits avec les cases à cocher vides à côté. Je coche certaines cases et rien n'est pris en compte quand je valide le formulaire, les produits ont toujours leur attribut checked à false alors que la case à cocher devrait le leur mettre à "true".

Je ne vois pas bien où est l'erreur.

Merci d'avance pour vos conseils,

Arnaud