I have a form to set values for bean. This form has a List, every address consist of street, city, zip. How to set value of street for example to street ?
Piece of code
//List
List<Address> addressList ; //with getter and setter
//Address POJO with getters and setters
private String city;
private String zipCode;
private String street;
//JSP
<form:form id="form" commandName="form" acceptCharset="UTF-8">
<c:forEach items="${form.addressList}" var="ad">
<input value="${ad.street}" id="addressList"name="addressList.street" type="text" />
</c:forEach>
</form:form>
$.ajax({
type : "POST",
url : url,
data : $('#form').serialize(),
contentType : "application/x-www-form-urlencoded;charset=UTF-8",
I'm sending form by ajax to controller. With List of Strings I'm getting in controller expected results, but with this POJO I'm getting null value.
How to solve this problem ?
You addressList
is not a part of Form and you are reading it from form object.
<c:forEach items="${form.addressList}" var="ad">
It should be
<c:forEach items="${addressList}" var="ad">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.