I have a spring 3 application with select list.
<form:select path="objectlist" >
<c:forEach items="${objects}" var="objects">
<form:option value="${objects}" label="${objects.description}" >
</form:option>
</c:forEach>
</form:select>
There objects are queried from database. Path is Object class attribute.
I would like to print the description of an object user has chosen.
When I u开发者_StackOverflow中文版se ${form.objects}
- I get an object instance written, but when adding .description
there, it is null
. What I'm missing here?
In <c:foreach>
tag you should specify the variable where it will temporary store each array element. For some reason you are using same name as an array and at some point the two variables collide with each other.
Try this:
<c:forEach items="${objects}" var="object"> <%-- Notice there is no letter S at the end --%>
<form:option value="${objects}" label="${object.description}" > <%-- Here too --%>
</form:option>
</c:forEach>
精彩评论