2010-05-05 69 views
2

在我的控制器中,我添加了一个ArrayList到属性名为“users”的模型中。形式为spring-mvc binding arraylist

现在我环顾四周,这是我发现的(包括在此问题)的方法:

<form:form action="../user/edit" method="post" modelAttribute="users"> 
      <table> 
       <c:forEach var="user" items="${users}" varStatus="counter"> 
        <tr> 
         <td> 
           <form:input path="users[${counter.index}].age"/> 
         </td> 
         <td><button type="submit" name="updateId" id="Update" value="${user.id}">Update</button></td> 
        </tr> 
       </c:forEach> 
      </table> 
     </form:form> 

但是当我加载JSP页面中我得到:

.springframework.beans。 NotReadablePropertyException: Bean的无效属性'projects [0]' class [java.util.ArrayList]:Bean property'users [0]'is not readable or has invalid invalid get method:Does the retu该吸气剂的类型是否与匹配器的参数类型 匹配?

因此设想这不是要走的路,但在那种情况下,我该如何绑定一个数组列表,以便我可以编辑值?

+0

您可以添加的代码数据发送的控制器方法? – Javi 2010-05-07 15:49:39

回答

1

尝试下面的代码:

<c:forEach var="user" items="${users}"> 
    <tr> 
      <td><c:out value="${users.age}"/></td> 
    </tr> 
</c:forEach> 

,并确保你有用户在请求范围的ArrayList ..或者使用添加以下代码:

<jsp:useBean id="users" scope="request" type="java.util.Collection" />