0

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)

2 Answers2

0

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.

Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
  • how can we do that with spring..just some hint will be useful –  Sep 21 '12 at 01:59
  • validation is not that critical..I will go with client side..thank you –  Sep 21 '12 at 01:59
  • 1
    @srinathveda: read [this](http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/) and [this](http://stackoverflow.com/questions/1673656/how-to-use-ajax-jquery-in-spring-web-mvc) – Janus Troelsen Sep 21 '12 at 11:02
0

For validation on server side for the fields you can refer the following post by me. Its kind of similar to your question. Please refere this question and answer by me.

Hope this helps you. Cheers

Community
  • 1
  • 1
Japan Trivedi
  • 4,445
  • 2
  • 23
  • 44