2
\$\begingroup\$

I have a JSP page with a table containing data from java.util.List. The items from the list are taken from the database.

  • Each row has an edit button that will get all the values from that specific row to be edited on another page.
  • Each row has a checkbox where if selected means it will be deleted from the table. The "delete all" button at the end will do the batch delete.

I think I can do this very easily with nested forms, placing the update form inside the delete form and calling update form whenever an edit button is clicked. But since we are not aloud to do that, I created those forms separately instead and used HTML5's form attribute to refer to delete form.

Are there other, better ways of doing this, seeing that I can't do this in HTML4 for compatibility with older browsers, but I don't care about compatibility that much at this time. I just feel this code is too ugly. How can I improve my code?

<%@ include file="design/header.jsp" %>
<body>
    <h3>Reservation List</h3>
    <form id="delete" action="deletereservations.html" method="post"></form>
    <table>
        <tr>
            <td>Check In Date</td>
            <td>Check Out Date</td>
            <td>Room Type</td>
            <td>Status</td>
            <td>Action-Edit</td>
            <td>Action-SELECT Delete</td>
        </tr>
        <c:forEach var="reservation" items="${reservations}"> 
            <tr>
                <td>${reservation.strCheckInDate}</td>
                <td>${reservation.strCheckOutDate}</td>
                <td>${reservation.roomType}</td>
                <c:choose>
                    <c:when test="${reservation.status eq 1}">
                        <td>approved</td>       
                    </c:when>
                    <c:when test="${reservation.status eq 2}">
                        <td>pending</td>
                        <td>
                            <form action="updatereservation.html" method="post">
                                <input type="hidden" name="checkInDate" value="${reservation.strCheckInDate}">
                                <input type="hidden" name="checkOutDate" value="${reservation.strCheckOutDate}">
                                <input type="hidden" name="roomType" value="${reservation.roomType}">
                                <input type="hidden" name="id" value="${reservation.reservationID}">
                                <input type="image" src="images/edit.jpg" height="30" width="30"  value="edit">
                            </form>
                        </td>
                        <td>
                            <input type="checkbox" name="id" value="${reservation.reservationID}" form="delete">
                        </td>
                    </c:when>
                    <c:when test="${reservation.status eq 3}">
                        <td>denied</td>
                    </c:when>
                </c:choose>
            </tr>
        </c:forEach>
    </table>
    <input type="image" src="images/delete.jpg" height="30" width="30"  name="deleteall" value="delete all" form="delete">
<%@ include file="../design/footer.html" %>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.