开发者

spring-mvc binding arraylist in form

In my controller I added an ArrayList to my model with the attribute name "users".

Now I looked around and this is the method I found (including a question here):

<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>

But when I load the JS开发者_运维百科P page I get:

.springframework.beans.NotReadablePropertyException: Invalid property 'projects[0]' of bean class [java.util.ArrayList]: Bean property 'users[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

So apparantely this isn't the way to go, but in that case how do I bind an arraylist so I can edit the values?


Try following code :

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

and make sure that you have users arraylist in the request scope.. Or else use add following code:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜