Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring input path for list

Tags:

spring-mvc

jsp

I am using Spring input path in jsp

ex:

<div class="cell label"> 
    <form:label path="order.paymentTransactions.payerEmail">Payer Mail</form:label>
</div> 
<div class="cell"> 
    <form:input path="order.paymentTransactions.payerEmail" name="payerEmail"/>
</div> 

here, order is my main object and inside order, paymentTransaction is a List, i have to input data to check through dao in payerEmail.

But it showing error to me and invalid path. Please suggest me a good way to define the input path in jsp. thanks

like image 872
user1894465 Avatar asked Dec 12 '12 10:12

user1894465


2 Answers

While mapping a list of bean in Spring, it is difficult to provide path attribute. You can replace the <form:input> with plain html <input>.

<input name="order.paymentTransactions[0].payerEmail" />

Here's a complete example to map List as form object in Spring MVC

Example: Spring MVC: Multiple Row Form Submit using List of Beans

The above example also discuss why it is difficult to use <form:input> while working with Lists. Its because if you try to use something like below:

<form:input path="order.paymentTransactions[0].payerEmail" name="payerEmail"/>

Spring will simple render this as HTML:

<input name="order.paymentTransactions0.payerEmail" />

Ignoring the brackets [ ].

Thus its impossible to use <form:input> for mapping List.

like image 80
Viral Patel Avatar answered Oct 18 '22 14:10

Viral Patel


We can do mapping of list through spring . Please update in your site. Thank you.

Example:

<c:forEach var="marksList" items="${personDTO.marksList}" varStatus="status">

<form:input path="marksList[${status.index}].hindi" />
like image 25
Sunil Avatar answered Oct 18 '22 15:10

Sunil