0

I have a web application struts 2 with a page that displays a table with various elements on several lines. These elements are in textfield boxes so you can modify them and then press a submit button to send the new values.

The submit button is present on each line so I would like that when you press the button, it gets the fields of the corresponding line except that in my case, it always gets the first line.

here is a part of my jsp page

<table border="1" >
            <thead>
            <col align="char">
            <tr bgcolor="#939393">


            <td><s:text name="chu.numero_patient" ></s:text></td>
            <td><s:text name="chu.numero_matelas"></s:text></td>
            <td><s:text name="chu.date_scanner"></s:text></td>
            <td><s:text name="chu.date_mep"></s:text></td>
            <td><s:text name="chu.nb_actuel"></s:text></td>
            <td><s:text name="chu.nb_total"></s:text></td>
            <td><s:text name="chu.date_ftr"></s:text></td>
            <td><s:text name="chu.remarques"></s:text></td>


            </tr>
            </thead>

            <s:iterator value="list" >
            <s:form id="id" method ="post" action="enregistrer_Developpeur">


                <tr>

                    <td><s:textfield name="numero_patient" id="numero_patient" theme="simple" size="15" ></s:textfield></td>                                             
                    <td><s:textfield name="numero_matelas" id="numero_matelas" theme="simple" size="6" ></s:textfield></td>
                    <td><s:textfield name="date_scanner" id="date_scanner" theme="simple" size="12"> </s:textfield></td>        
                    <td><s:textfield name="date_mep" id="date_mep" theme="simple" size="8"></s:textfield></td>
                    <td><s:textfield name="nb_actuel" id="nb_actuel" theme="simple" size="27"></s:textfield></td>       
                    <td><s:textfield name="nb_total" id="nb_total" theme="simple" size="25"></s:textfield></td>
                    <td><s:textfield name="date_ftr" id="date_ftr" theme="simple" size="7"></s:textfield></td>      
                    <td><s:textfield name="remarques" id="remarques" theme="simple" size="10"></s:textfield></td>
                    <s:textfield name="id" value="%{id}" theme="simple" size="15" ></s:textfield>
                    <s:submit  form ="id" value = "Modifier" align="center"></s:submit>
            </tr>


        </s:form>

        </s:iterator>

        </table>

How can I do that ?

Seyn
  • 1
  • You have a form with multiple elements with the same name; it'll take the first (or the last, dunno). You either need (a) multiple forms, or (b) JS to handle only the line you're on. – Dave Newton Apr 02 '19 at 18:39
  • Thank you for the answer, make several forms seems complicated to me if I have many lines and the number of lines will not be fixed. The solution with JS seems interesting to me but I do not know how it works, if you have the time I want you to tell me more. – Seyn Apr 02 '19 at 20:35
  • The number of forms on a page isn't really relevant (and if you have *that* many rows you have other UX issues). The JS would be trivial; each row's name or ID would be indexed, and the submit button would call a function with that index, get the related form fields, and submit. – Dave Newton Apr 02 '19 at 20:53
  • May be this answer will help you https://stackoverflow.com/a/27795881/573032 – Roman C Apr 05 '19 at 10:57

0 Answers0