[Struts] récupération des valeurs de checkbox dynamiques
	
	
		Ca avance ca avance :) J'ai trouvé comment récupérer les valeurs de mes checkbox. Il fallait à l'instanciation de la String [] dans le Form, indiquer dynamiquement la taille du tableau à créer, dans mon cas le nombre de produit. Le hic c'est que je n'arrive pas à identifier laquel est selectionnée...
Je m'explique. Dans le ActionBean je récupère les valeurs du form:
	Code:
	
        String Souche [] = CartForm.getId();
 J'affiche les valeurs de cette string avec un system.out.println.
J'ai deux produits, donc deux checkbox. Je selectionne la deuxieme et je clic sur mon bouton. il me dis:
produit 0 = on. 
Je selectionne la premiere et je clic sur mon bouton:
produit 0 = on.
Comment pourais-je faire pour identifier ma checkbox avec le commande_Id que j'ai dans mon ArrayList? Voici les extraits de mon code. J'espère que c'est assez clair, merci d'avance pour le coup de pouce :)
JSP:
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 
 | <%
ArrayList tableau = new ArrayList();
tableau = SwCallId.AGetInfoCart(user,pass,base);
session.setAttribute("tableau", tableau);
int sizeZ= tableau.size();
ShowCartFormId.size_tab(sizeZ);
%>
 
 
<html:form action="/showCart" name="showCart" type="com.InraLgmpa.struts.form.ShowCartForm">
<table border="0" align="left">
 
<logic:iterate id="element" name="tableau">
<tr>
 
<TD><html:checkbox name="element" property="id" ></html:checkbox>    </TD>
<TD><b><font color="blue"><bean:write name="element" property="Id_Souche"/></font></b></TD>  
<TD>    </TD> 
<td><b> Date: </b></td>  
<TD><font color="blue"><bean:write name="element" property="date"/><br></font></TD>  
<TD>    </TD> 
<td><B> Amount: </B> </td>   
<td>  <font color="blue"><bean:write name="element" property="quantite"/></font></td>
</tr>
</logic:iterate> | 
 
BeanAction:
  
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 
 |       public ActionForward delete(
            ActionMapping mapping, 
            ActionForm form, 
            HttpServletRequest request, 
            HttpServletResponse response) throws IOException, ServletException {
            ShowCartForm CartForm = (ShowCartForm) form;
 
            String Souche [] = CartForm.getId();
            int sizeounette = Souche.length;
            for (int po=0; po<sizeounette; po++) {
                System.out.println("Delete: Produit N° "+po+"---"+ Souche[po]);
            }
            order = "N";
//            String delete_souche = SwCall.DeleteOrderCart(UserName, Password, bdd, Souche, order);
 
            // TODO Auto-generated method stub
            System.out.println("Click on >> DELETE");
            return mapping.findForward("oui");                
        } | 
 FormBean:
	Code:
	
| 12
 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
 
 | public class ShowCartForm extends ActionForm {
 
    // --------------------------------------------------------- Instance Variables
    /** profil property */
    private String hidden;
    static int taille=0;
 
 
    public static int size_tab(int size) {
        taille = size;
        return taille;
    }
    private String []id = new String[taille];
 
    // --------------------------------------------------------- Methods
    /**
     * @return Returns the hidden.
     */
    public String getHidden() {
        return hidden;
    }
    /**
     * @param hidden The hidden to set.
     */
    public void setHidden(String hidden) {
        this.hidden = hidden;
    }
    /**
     * @return Returns the id_Souche.
     */
 
    /**
     * @return Returns the id.
     */
    public String[] getId() {
        return id;
    }
    /**
     * @param id The id to set.
     */
    public void setId(String[] id) {
        this.id = id;
    } |