I have complex form objects, with unlimited depth and I’m trying to edit them on jsp with spring form tags.
Main modelAttribute is bind to spring form, and while I’m iterating through childs, I use nestedPath and everithing works OK. As result I have generated input names something like:
name="elements['secondColumn'][0].elements[0].removed"
Problem is that I can not know the generated name. Why I need it? Let’s say that I have delete button from which I want to set appropriate field “removed” to 1.
Update:
How does it works? I am using tag files which are recursively calling them self.
container.tag
<c:forEach items="${elements}" var="element" varStatus="index">
<spring:nestedPath path="elements[${index.count - 1}]">
<my:elementConfig element="${element}">
<my:container elements="${element.elements}"/>
</my:elementConfig>
</spring:nestedPath>
</c:forEach>
elementConfig.tag
...
<form:hidden path="removed"/>
...
<button onclick="delete('howToGetNameOfRemovedHidden')">Delete</button>
...
<jsp:doBody/>
...
Closest match I allready found is a “nestedPath” pageContext attribute, but it contains the name of the modelAttribute (form) name too.
Is there official way to get the generated name?
Thanks
As it seems there is no official support for getting generated input names, so I’ve made a function which handles it. It is based on a functionality I found in Spring form tag library.
Static methods:
tld definition:
Example usage: