Hi,
I am having difficulty getting spring:bind to work on a list.
My object graph is a little complicated, but if I can get this to work, I can use it over many pages, so I think it is worth the effort.
Here are the relevant objects:
Code:public class ProfileInfo extends AbstractInfo { List populatedSelects; .... including getters/setters... }Code:public class PopulatedSelect { private Select select = new Select(); private AttributeRating attributeRating = new AttributeRating(); .... including getters/setters...Code:public class Select { private String name; private String title; private String category; private List options = new ArrayList(); private int selected; .... including getters/setters...features.jsp:Code:public class AttributeRating { private String userName; private String attributeName; private int rating = 0; .... including getters/setters...
I have had to use a Select object, because I have many pages using a variable number of selects, and I needed to keep all these properties in an XML file. I need the AttributeRating object because later I want to make it so that is a user doesn't like any of the options offered in a select, he can fill in his own value into a textfield - but I have removed this code for now.Code:<TABLE> <c:forEach items="${profileInfo.populatedSelects}" var="populatedSelect" varStatus="varStatus"> <TR><td><c:out value="${populatedSelect.select.title}"/></td> <TD> <spring:bind path="profileInfo.populatedSelects[${varStatus.index}].attributeRating.rating"> <select name="<c:out value="${populatedSelect.select.name}"/>" size="1"> <c:forEach items="${populatedSelect.select.options}" var="option"> <option <c:if test="${populatedSelect.attributeRating.rating == option.index}">selected</c:if> value="<c:out value="${option.index}"/>"><c:out value="${option.value}"/></option> </c:forEach> </select> </spring:bind> </TD> </spring:bind> </TR> </c:forEach> </TABLE>
It all works in the display, except that the value selected in the select options doesn't get bound to the field AttributeRating.rating.
Adding the line:
after the spring:bind tag outputs the correct value for attributeRating.rating for each tag.Code:rating test = <c:out value="${profileInfo.populatedSelects[varStatus.index].attributeRating.rating}"/>
I guess I have something wrong in the spring:bind tag - can anyone help?
Many thanks,
John Pedersen


Reply With Quote