Hi,
I am working on my first Spring MVC project, and using the tags/form taglib.
The data object behind the form has one field which is a Map<String,String>. There are no restrictions on the keys and values in the data model, but for this particular form the set of keys is fixed while the user may change the values.
In the non-Spring predecessor of this project, this was done as follows:
where keyNames is populated in the controller with the keys from the map.Code:<c:forEach var="keyName" items="${keyNames}" varStatus="iter"> <label for="key-${iter.index}">${keyName}</label> <input type="text" name="key-${keyName}" id="key-${iter.index}" value="${entity.partsMap[keyName]}"/> </c:forEach>
I would like to replace this with something like the following (which of course does not work!)
or even better, do away with the need for the keyNames list.Code:<c:forEach var="keyName" items="${keyNames}" varStatus="iter"> <label for="key-${iter.index}">${keyName}</label> <form:input path="partsMap[keyName]"/> <form:errors path="partsMap[keyName]"/> </c:forEach>
(and better still, change the form:input for a form:select!)
Is any of this possible? I will be very grateful to anyone who can point me in the right direction...
Thanks,
Alex


Reply With Quote
