I was trying to bind POJO using spring form
tag library. After binding reference class bean variables, I am getting "Bad Request Error- Http Status 400".
If I remove binding of reference class, My form is submitted successfully and values are also populated inside the class.
public class EmployeeTourPojo {
private String empDisplayName;
private List<TourDetailsPojo> tourDetails;
//getter and setter
}
and
public class TourDetailsPojo {
private Date departDate;
private String departTime;
//getters and setters
}
JSP:
<td><form:input path="empDisplayName" class="form-control"/> </td>
<form:input placeholder="Departure Date" path="tourDetails[${index}].departDate" required="required" class="datepicker form-control"/><br/>
I had got references from few articles but they are loading the list of reference bean at the get request while I am adding the rows before the submitting the JSP.
I found the issue lies in incrementing the index after Clicking "Add Row". Hence, I had added following JQuery code to increment index.
$("#addRow").click(function(){
//alert("The button was clicked.");
var addressRow = $('.repeat-address').last();
var addressRowLength = $('.repeat-address').length;
var newAddressRow = addressRow.clone(true).find("input").val("").end();
$(newAddressRow).find("td input,td select").each(function(index,item) {
item.name = item.name.replace(/[0-9]/g,addressRowLength);
});
newAddressRow.insertAfter(addressRow);
});
HTML CODE
<c:set var="index" value="0"/>
<td><form:input path="empDisplayName" class="form-control"/> </td>
<tr class="repeat-address">
<td>Departure Date</td>
<td><form:input placeholder="Departure Date" path="tourDetails[${index}].departDate" required="required" class="datepicker form-control"/></td>
<td>Pincode</td>
<td><input type="text" name="tourDetails[${index}].departDate"/></td>
<td><input type="file" name="tourDetails[${index}].tourTicket"/></td>
</tr>
<tr><td colspan="3"><input id="addRow" type="button" value="Add Row"></td></tr>
Since, I also need to bind input type file with POJO. I had also Added one Multipart field (in TourDetailsPojo Bean) as
private Date departDate;
private Multipart tourTicket;
//getters and setters