10

我有一个命令对象FaxForm,它包含一个属性 FaxStatus内的对象列表。faxStatusList

public class FaxForm {
  private List<FaxStatus> faxStatusList;
  public void setFaxStatusList(List<FaxStatus> faxStatusList) {
    this.faxStatusList = faxStatusList;
  }
  public List<FaxStatus> getFaxStatusList() {
    return faxStatusList;
  }
}

我最初有一个 JSP 页面,它通过执行以下操作来绑定对象:

<c:forEach items="${esaFaxForm.faxStatusList}" var="item" varStatus="loop">
  <tr class="tableAltBackground">
    <td>
      <form:checkbox path="faxStatusList[${loop.index}].selected"/>
    </td>
    <td>
      <form:select path="faxStatusList[${loop.index}].status" items="${esaFaxForm.statusOptions}" onchange="checkThisBox(this);"/>
    </td>
    <td>
      <a href="${statusContUrl}?id=${item.id}&status=${item.status}" onclick="openFaxWindow('${viewFaxUrl}?id=${item.id}', ${loop.index});">${item.name}</a>
      <form:hidden path="faxStatusList[${loop.index}].name"/>
    </td>
    <td>
      <a href="${statusContUrl}?id=${item.id}&status=${item.status}" onclick="openFaxWindow('${viewFaxUrl}?id=${item.id}', ${loop.index});">${item.id}</a>
      <form:hidden path="faxStatusList[${loop.index}].id"/>
    </td>
  </tr>
</c:forEach>

但是,我试图弄清楚如何在没有 forEach 循环和索引的情况下进行绑定。Spring网站上的示例通过将路径设置为列表名称来显示绑定。有没有办法绑定属性?我已经尝试过了,但它失败了:

<form:checkbox path="faxStatusList.faxStatus.selected"/>
<form:select path="faxStatusList.faxStatus.status" items="${esaFaxForm.statusOptions}"/>

传真StatusList 有一个getter 和setter 方法,而FaxStatus 变量每个都有getter/setter 属性。我收到错误“bean 类的无效属性'faxStatusList.faxStatus'...”

4

1 回答 1

9

Spring form tags has a checkboxes tag. You can use it as follows to do the binding automatically:

<form:checkboxes items="${faxStatusList}" path="faxStatusList" itemLabel="name" itemValue="id" delimiter="<br/>" onclick="yourOnClickMethodIfYouNeed(this);"/>

The above snippet will display a list of checkbox items delimited with the br tag. Any changes made to the state of the checkboxes will be reflected appropriately in your FaxForm. faxStatusList object.

于 2009-12-21T18:42:40.743 回答