RYJ
RYJ

Reputation: 439

Pass the value from Spring form to another spring form

I'm doing a project using Spring MVC and Hibernate and I'm still learning them. This is my question. I've created following table on BookInfo.jsp page.

<table class="table table-bordered table-hover table-striped ">
    <thead>
        <tr>
            <th>Book Id</th>
            <th>Book price</th>
        </tr>
    </thead>

    <tbody>
        <form:form commandName="res" action='/bookshop/book-order.html'>
            <c:forEach items="${BookInfo}" var="bookInfo">
                <tr>
                    <td>${bookInfo.id}</td> 
                    <td>${bookInfo.price}</td>
                    <td><input type="submit" value="Order now"></td>
                </tr>
            </c:forEach>
        </form:form>
    </tbody>
</table>

I need to pass the values of book.price to below bookOrder.jsp page when once I clicked submit button. There may be 3 or 4 rows as follows.

Image of the table

If I clicked the button in first row, 500 should be passed to the <form:label path=""></form:label> section in following jsp page

<form:form commandName="reservation" cssClass="form-horizontal" >

  <div>
    <label for="customerName">Name</label>
    <div>
      <form:input path="customerName"/>
    </div>
  </div>

   <div>
    <label for="bookPrice" >Book price</label>
    <form:label path=""></form:label>
  </div>

  <input type="submit" value="Save"/>   
</form:form>

How can I do this linking in Spring MVC ? Appreciate your help. I have removed unnecessary codes for easy reading

Upvotes: 1

Views: 1391

Answers (1)

First, you can use it by passing the value as a model attribute in your controller and reusing it as a hidden (or readonly) field in the view.

Second, don't do that: Never trust information sent from the client. It'll be laughably simple to change the form value to 1 for a really nice discount. Pass just the product ID and look up the price server-side instead.

Upvotes: 2

Related Questions