I have a table, following is my code:
<table id="div1" style="display:none">
<tr><td>Host Name</td><td>Directory</td><td>User Name</td><td>Password</td></tr>
<c:if test="${empty location.fEvents}">
<tr><td><form:input path="userEnteredHostNameString" size="30" maxlength="200"/></td>
<td><form:input path="userEnteredDirectoryString" size="30" maxlength="200"/></td>
<td><form:input path="userEnteredUserNameString" size="20" maxlength="20"/></td>
<td><form:input path="userEnteredPasswordString" size="20" maxlength="20"/></td>
</tr>
</c:if>
<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>
</table>
whatever this ${location.fEvents} comes to either empty or with values..if User wants…user can add/delete a row and the values of the row should save back in the database..
what is the best way to do it..can we do it in spring or we need to use javascript..suggestions are really appreciated
EDITED: How can add validation errors to these fields if they are empty or null(just to the above code without javascript)
You can do it with both Spring and JavaScript. But if the data is supposed to change on the backend, you need to make JavaScript do XHR requests. Google “JavaScript AJAX”.
About validation:
If your validation is not critical (i.e. only a convenience) you can do it client-side.
If your validation is “critical”, you should first implement it on the server, and then when it works perfectly you can implement a simpler version for the client so they don’t have to reload as much. Using GWT you can share the validation code.