java - Displaying List elements in JSTL <c:/forEach> with counter variable -
i have scriptlet for-loop displays movie schedules list<schedule>
.
<% @suppresswarnings("unchecked") list<schedule> schedulelist = (arraylist<schedule>) session.getattribute("schedulelist"); (int ctr = 0; ctr < schedulelist.size(); ctr++) { %> <tr> <td class="center"> <input type="radio" name="selection" value="<%=ctr%>" required title="please select schedule." /> </td> <td><%=schedulelist.get(ctr).getmallid()%></td> <td class="center"><%=schedulelist.get(ctr).getschedulecinema()%></td> <td>php <%=schedulelist.get(ctr).getscheduleprice()%></td> <td><%=schedulelist.get(ctr).getscheduledate()%></td> <td><%=schedulelist.get(ctr).getscheduletime()%></td> <td class="center"><%=schedulelist.get(ctr).getscheduleseats()%></td> </tr> <% } %>
here schedule
bean object reference:
public class schedule { private int scheduleid; private int movieid; private string mallid; private int schedulecinema; private bigdecimal scheduleprice; private date scheduledate; private time scheduletime; private int scheduleseats; // getters , setters }
i have managed convert jstl desired number of iterations (related thread).
<c:foreach var="ctr" begin="0" end="${schedulelist.size()-1}"> <tr> <td class="center"> <input type="radio" name="selection" value="${ctr}" required title="please select schedule." /> </td> <td>${schedule.mallid}</td> <td>${schedule.schedulecinema}</td> <td>${schedule.scheduleprice}</td> <td>${schedule.scheduledate}</td> <td>${schedule.scheduletime}</td> <td>${schedule.scheduleseats}</td> </tr> </c:foreach>
output:
firefox inspector:
<tr> <td class="center"> <input type="radio" title="please select schedule." required="" value="0" name="selection"></input> </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td class="center"> <input type="radio" title="please select schedule." required="" value="1" name="selection"></input> </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>
unfortunately, schedule details not displaying.
how display data of each schedule
element list<schedule>
in jstl?
(the ctr
important way, value needed in next action.)
instead of
<c:foreach var="ctr" begin="0" end="${schedulelist.size()-1}">
use:
<c:foreach var="schedule" items="${schedulelist}" varstatus="ctr"> <tr> <td class="center"> <input type="radio" name="selection" value="${ctr.index}" required title="please select schedule." /> </td>
for ctr maintain separate counter variable , increment within foreach.
Comments
Post a Comment