Java Quiz Player

Blog Post

JSP: Select and Process Table Row Data

May 14, 2014

Case 2: Using Checkboxes to Select the Row Data

1. Room Selection form:

image 2a

In the page the search result data is displayed in rows using JSTL tags with data from the session attribute availableRooms. Each row is displayed with a checkbox as a column value.

The following is the code snippet to display the available rooms:

<c:forEach var="room" items="${sessionScope.availableRooms}" 
varStatus="status"> ${} ... <input type="checkbox" name="checkButton" value="${status.count}"> </c:forEach>

The value attribute of checkbox has the ${status.count} value. This is the current round of iteration (and this starts from 1, not zero).

The user selects table row(s) by checking the checkbox(es). Then submits the form by clicking the Reserve button; and this action takes to the Reservation form.

Note that one or more rows can be processed on submitting the form, i.e., multiple rooms can be reserved by the clerk at a time.

2. Reservation form:

The selected row indexes in the Room Selection form are available in this form as request parameter (name checkButton) values. Get the parameter values and reduce each value by 1 (The availableRooms is a List collection and its index starts from zero. The parameter value has the table iteration count starting from 1. To get the correct List index from displayed row, reduce the parameter value by 1):

Iterate over request parameter values, get the table row values from the availableRooms session variable using the row index.

The following is the code snippet to show the selected row data:

<c:forEach var="rowno" items="${paramValues.checkButton}" >
image 2b

Details to complete the reservation process are entered (guest and payment info, reservation dates etc.,) and the form is submitted for the reservation confirmation.

The Confirmation form shows the hotel room reservation confirmation details (this form's screenshot is not shown in this post).

<< Back to the post | Continue to Case 3 >>

Return to top


Comments are welcome. Please note that comments are moderated.
Email to: info(at)javaquizplayer(dot)com.