0
<c:forEach var="programSlot" items="${programSlot}" varStatus="status">
    <tr>
        <td>
            <input name ="duration" value="${programSlot.duration}" disabled />
        </td>
        <td>
            <select name= "programName">
                <c:forEach var="radioProgram" items="${rps}"> 
                    <c:choose>
                        <c:when test="${radioProgram.name == programSlot.programName}">
                            <option value="${radioProgram.name}" selected="">${radioProgram.name}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${radioProgram.name}">${radioProgram.name}</OPTION>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select>
        </td>
        <td><input name ="startTime"  value="${programSlot.startTime}" /></td>
        <td> <input name ="dateOfProgram" disabled value="${programSlot.dateOfProgram}" /></td>    
        <td>
            <input type="submit" value="Submit"/>

[In the attached image, I have shown my web form. Each row is showing attribute values of an object.

Now I want that if I change some value of a particular row and click on "submit" the values should get saved in request parameter. (So that I can fetch the same in my java file to set those values and save in db.)

I want to do this using JSTL (or any other solution is welcome)]1

enter image description here

I have also attached code snippet.

Sayali Sonawane
  • 12,289
  • 5
  • 46
  • 47
Yoda
  • 323
  • 6
  • 14

1 Answers1

0

Parameters in request are automatically added when form is submitted using POST. Use the tag's "name" attribute to get them from request.

Example:

<input name ="startTime" ...

request.getParameter("startTime"); ...

request.getParameter("programName");

EDIT: Move submit button out of the loop. Add index to each element. Example:

            <select name= "programName_"${loop.index}>

Iterate the lists like programSlot in java to fetch values from request and set in object. Example:

request.getParameter("programName_"+i);

Could also use request.getParameterValues depending upon element type.

Stacky
  • 503
  • 2
  • 6
  • 23
  • But I need to differentiate as to know which submit button was clicked (as each row should update in different object. – Yoda Sep 24 '16 at 03:45
  • The snippet shows only one button, so more details are needed. Usually, you would not require multiple submit buttons in most situations. If required, see this: http://stackoverflow.com/questions/2129346/if-an-html-form-has-two-input-type-submit-buttons-how-do-i-know-which-got-c – Stacky Sep 24 '16 at 03:53
  • the button is in for loop. So for each row a button is there. – Yoda Sep 24 '16 at 03:56
  • see edited answer – Stacky Sep 24 '16 at 04:07
  • Thanks my problem is solved. It works now :) – Yoda Sep 24 '16 at 12:10
  • Great :) , please accept this as an answer if it helped – Stacky Sep 24 '16 at 13:28