2

这是我的spring mvc jsp代码片段

<c:forEach var="trackRecord"  varStatus = "number" items="${contractDetails.trackRecordEntries}" >
  <tr class="tafont">
      <td class="varcar"><form:input readonly = "true" name = "installmentNo" id = "installmentNo" path="trackRecordEntries[${number.index}].installmentNo"/></td>
      <td class="varcar"><form:input readonly = "true" name  = "installmentAmount" id = "installmentAmount" path = "trackRecordEntries[${number.index}].installmentAmount"/></td>   
      <td class="varcar"><form:input readonly = "true" name = "dueDate" id = "dueDate" path="trackRecordEntries[${number.index}].dueDate"/></td>
      <td class="varcar"><form:input cssClass="recievedDate" name = "recievedDate" id = "recievedDate" path="trackRecordEntries[${number.index}].recievedDate"/></td>
      <td class="varcar"><form:input id = "recieptAmount" name = "recieptAmount" path="trackRecordEntries[${number.index}].recieptAmount"/></td>
      <td class="varcar"><form:input id = "delayDays" name = "delayDays" path="trackRecordEntries[${number.index}].delayDays"/></td>     
 </tr>
 </c:forEach>

它将bean的arraylist绑定到jsp页面。问题是我不能使用带有标签的“ name”属性。<form:input>我需要 name 属性,因为我想使用执行 javascript 验证document.getElementsByName("name");

任何解决方案??

4

2 回答 2

2

当您使用 Spring 标签(即<form:input>)标签时,您不能在 spring标签中使用name属性。如果您想要name属性,那么您必须使用标签的path属性,该属性在内部将其值转换为HTML标签的name属性,如下所示:

<c:forEach var="trackRecord"  varStatus = "number" items="${contractDetails.trackRecordEntries}" >
  <tr class="tafont">
      <td class="varcar"><form:input readonly = "true" path = "installmentNo" id = "installmentNo" /></td>
      <td class="varcar"><form:input readonly = "true" path  = "installmentAmount" id = "installmentAmount" /></td>   
      <td class="varcar"><form:input readonly = "true" path = "dueDate" id = "dueDate" /></td>
      <td class="varcar"><form:input cssClass="recievedDate" path = "recievedDate" id = "recievedDate" /></td>
      <td class="varcar"><form:input id = "recieptAmount" path = "recieptAmount" /></td>
      <td class="varcar"><form:input id = "delayDays" path = "delayDays" /></td>     
 </tr>
 </c:forEach>

并且您必须将所有这些路径变量定义到您的表单中,如下所示:

public class UoyrForm {

    private String[] installmentNo;
    private String[] installmentAmount;
    private String[] dueDate;
    private String[] recievedDate;
    private String[] recieptAmount;
    private String[] delayDays;
}

或者您可以使用简单的 HTML 标签

于 2013-09-25T07:37:41.317 回答
0

为什么不使用 document.getElementById("id value here"),因为您定义了唯一的 id 值,并且 name 属性在这里是多余的

于 2013-09-25T07:49:00.183 回答