spring input path for list

2020-02-11 04:59发布

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

3条回答
可以哭但决不认输i
2楼-- · 2020-02-11 05:45

You can do these:

<c:set var="list" value="order.paymentTransactions[0].payerEmail" scope="page" />

<form:input path="${list}" name="payerEmail"/>

These worked for me.

查看更多
冷血范
3楼-- · 2020-02-11 05:47

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.

查看更多
We Are One
4楼-- · 2020-02-11 05:57

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" />
查看更多
登录 后发表回答