This is my Code for Jsp to iterate through the list
<c:forEach items="${location.fEvents}" var="item" varStatus="loop">
<tr><td><form:input path="fEvents[${loop.index}].hostName" size="30" maxlength="200"/></td>
<td><form:input path="fEvents[${loop.index}].directory" size="30" maxlength="200"/></td>
<td><form:input path="fEvents[${loop.index}].userName" size="20" maxlength="20"/></td>
<td><form:input path="fEvents[${loop.index}].password" size="20" maxlength="20"/></td>
</tr>
</c:forEach>
My code in controller:
while (location.getfEvents().size() < 3) {
FtpScanEvents f = new FtpScanEvents();
f.setLocation(location);
location.getfEvents().add(f);
}
whenever there is new entry, My jsp displays three empty rows, If user enters data in first row, It should save only that to database. But, my code is saving the other two empty rows as null to database. This is because I am using spring binding and iterating the list to show the values (JSP Code).
Any suggestion to avoid this!
Thanks in advance!
Check the fields for null and empty before inserting in the database.