tags:

views:

496

answers:

1

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

+1  A: 

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" />
Nirmal