Skip to content

AbstractDataBoundFormElementTag generates incorrect input name attribute when using indexed properties [SPR-7007] #11672

@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions