-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Tom Chambers opened SPR-7007 and commented
When binding to a list or map in a form tag, in my case:
<form:checkbox path="command[${mapkey}][${i.index}].aList" value="${aValue}" />
The checkbox is correctly bound and rendered (using a custom property editors etc), however on submission the request parameters are not correctly bound to the form object. After investigation it appears that the HTML "name" attribute of the input field is incorrect, before 3.0.1 (RELEASE-A) it would render:
<input id="commandkeyvalue0.aList.subscriptionMethods1" name="command[keyvalue][0].aList.subscriptionMethods1" type="checkbox" value="aValue" checked="checked"/>
<input type="hidden" name="_command[keyvalue][0].aList.subscriptionMethods1" value="on"/>
It now renders:
// Note the missing square brackets in the name
<input id="commandkeyvalue0.aList.subscriptionMethods1" name="commandkeyvalue0.aList.subscriptionMethods1" type="checkbox" value="aValue" checked="checked"/>
<input type="hidden" name="_commandkeyvalue0.aList.subscriptionMethods1" value="on"/>
I am aware that in 2.5 the "id" attribute of input fields were changed to remove the square brackets [ and ]. However it seems that the "name" also has these removed causing the request parameters to not be bound on submission of the form. Manually editing the HTML to include the [ and ] characters in the "name" attribute fixes the issue.
Although I have found this in using the portlet API and the form:checkboxes/ tag, I suspect that it is common in the servlet code (and other form tags) too - it seems to be in AbstractDataBoundFormElementTag:
In 3.0.0 (working):
protected String autogenerateId() throws JspException {
return StringUtils.deleteAny(getName(), "[]");
}
protected String getName() throws JspException {
return getPropertyPath();
}
In 3.0.1 RELEASE A:
protected String autogenerateId() throws JspException {
return getName();
}
protected String getName() throws JspException {
return StringUtils.deleteAny(getPropertyPath(), "[]");
}
Please feel free to shoot me down - I have spent a while on this and I cant see how the above is supposed to work.
Affects: 3.0.1
Issue Links:
- Spring web's tag library removes "[" and "]" in the path attribute for input (and possibly others). [SPR-6989] #11654 Spring web's tag library removes "[" and "]" in the path attribute for input (and possibly others). ("duplicates")