<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=tccham182" rel="nofollow">Tom Chambers</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7007?redirect=false" rel="nofollow">SPR-7007</a></strong> and commented</p>
<p dir="auto">When binding to a list or map in a form tag, in my case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;form:checkbox path=&quot;command[${mapkey}][${i.index}].aList&quot; value=&quot;${aValue}&quot;  /&gt;"><pre class="notranslate"><code class="notranslate">&lt;form:checkbox path="command[${mapkey}][${i.index}].aList" value="${aValue}"  /&gt;
</code></pre></div>
<p dir="auto">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:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;input id=&quot;commandkeyvalue0.aList.subscriptionMethods1&quot; name=&quot;command[keyvalue][0].aList.subscriptionMethods1&quot; type=&quot;checkbox&quot; value=&quot;aValue&quot; checked=&quot;checked&quot;/&gt;
&lt;input type=&quot;hidden&quot; name=&quot;_command[keyvalue][0].aList.subscriptionMethods1&quot; value=&quot;on&quot;/&gt;"><pre class="notranslate"><code class="notranslate">&lt;input id="commandkeyvalue0.aList.subscriptionMethods1" name="command[keyvalue][0].aList.subscriptionMethods1" type="checkbox" value="aValue" checked="checked"/&gt;
&lt;input type="hidden" name="_command[keyvalue][0].aList.subscriptionMethods1" value="on"/&gt;
</code></pre></div>
<p dir="auto">It now renders:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// Note the missing square brackets in the name
&lt;input id=&quot;commandkeyvalue0.aList.subscriptionMethods1&quot; name=&quot;commandkeyvalue0.aList.subscriptionMethods1&quot; type=&quot;checkbox&quot; value=&quot;aValue&quot; checked=&quot;checked&quot;/&gt;
&lt;input type=&quot;hidden&quot; name=&quot;_commandkeyvalue0.aList.subscriptionMethods1&quot; value=&quot;on&quot;/&gt;"><pre class="notranslate"><code class="notranslate">// Note the missing square brackets in the name
&lt;input id="commandkeyvalue0.aList.subscriptionMethods1" name="commandkeyvalue0.aList.subscriptionMethods1" type="checkbox" value="aValue" checked="checked"/&gt;
&lt;input type="hidden" name="_commandkeyvalue0.aList.subscriptionMethods1" value="on"/&gt;
</code></pre></div>
<p dir="auto">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.</p>
<p dir="auto">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:</p>
<p dir="auto">In 3.0.0 (working):</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
	protected String autogenerateId() throws JspException {
		return StringUtils.deleteAny(getName(), &quot;[]&quot;);
	}

	protected String getName() throws JspException {
		return getPropertyPath();
	}
"><pre class="notranslate">	<span class="pl-k">protected</span> <span class="pl-smi">String</span> <span class="pl-s1">autogenerateId</span>() <span class="pl-k">throws</span> <span class="pl-s1">JspException</span> {
		<span class="pl-k">return</span> <span class="pl-smi">StringUtils</span>.<span class="pl-en">deleteAny</span>(<span class="pl-en">getName</span>(), <span class="pl-s">"[]"</span>);
	}

	<span class="pl-k">protected</span> <span class="pl-smi">String</span> <span class="pl-s1">getName</span>() <span class="pl-k">throws</span> <span class="pl-s1">JspException</span> {
		<span class="pl-k">return</span> <span class="pl-en">getPropertyPath</span>();
	}</pre></div>
<p dir="auto">In 3.0.1 RELEASE A:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
	protected String autogenerateId() throws JspException {
		return getName();
	}

	protected String getName() throws JspException {
		return StringUtils.deleteAny(getPropertyPath(), &quot;[]&quot;);
	}
"><pre class="notranslate">	<span class="pl-k">protected</span> <span class="pl-smi">String</span> <span class="pl-s1">autogenerateId</span>() <span class="pl-k">throws</span> <span class="pl-s1">JspException</span> {
		<span class="pl-k">return</span> <span class="pl-en">getName</span>();
	}

	<span class="pl-k">protected</span> <span class="pl-smi">String</span> <span class="pl-s1">getName</span>() <span class="pl-k">throws</span> <span class="pl-s1">JspException</span> {
		<span class="pl-k">return</span> <span class="pl-smi">StringUtils</span>.<span class="pl-en">deleteAny</span>(<span class="pl-en">getPropertyPath</span>(), <span class="pl-s">"[]"</span>);
	}</pre></div>
<p dir="auto">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.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398103843" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11654" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11654/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11654">#11654</a> Spring web's tag library removes "[" and "]" in the path attribute for input (and possibly others). (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=egervari" rel="nofollow">Ken Egervari</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6989?redirect=false" rel="nofollow">SPR-6989</a></strong> and commented</p>
<p dir="auto">I have some code that purposefully puts "[" and "]" in the path, which eventually gets rendered to the id and name attributes on the input tag.</p>
<p dir="auto">Code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;@springForm.input type=type attributes=attributes path=path htmlEscape=&quot;true&quot; /&gt;&lt;br/&gt;"><pre class="notranslate"><code class="notranslate">&lt;@springForm.input type=type attributes=attributes path=path htmlEscape="true" /&gt;&lt;br/&gt;
</code></pre></div>
<p dir="auto">At a high level, it gets used like this:<br>
Code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;@form.text path=&quot;studentAnswer.answers[${chunk.text}]&quot; /&gt;"><pre class="notranslate"><code class="notranslate">&lt;@form.text path="studentAnswer.answers[${chunk.text}]" /&gt;
</code></pre></div>
<p dir="auto">Unfortunately, spring's tag library is removing the "[" and "]", so what is left over is a giant string value. I <strong>must</strong> use this pattern since this page has multiple input fields that are totally random based on the list of text chunks.</p>
<p dir="auto">Each form value is supposed to map to this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="private Map&lt;String,String&gt; answers = new HashMap&lt;String, String&gt;();"><pre class="notranslate"><code class="notranslate">private Map&lt;String,String&gt; answers = new HashMap&lt;String, String&gt;();
</code></pre></div>
<p dir="auto">Of course, when the server tries to get the values, there are NPE's everywhere due to Spring's stupidity.</p>
<p dir="auto">How did this break? I was using plain html before, and I just recently switched over to the tag library because it was the only way to get multipart's working correctly. Otherwise, Spring didn't pass the MultipartFile object to the domain object. I tried everything, and this is what fixed it.</p>
<p dir="auto">Now that I have converted about 50 forms to use the tag library, I have finally arrived to the 1 outlier form that does not covert over successfully. Sigh.</p>
<p dir="auto">Please tell me how I can get this to work so I can get this production code launched.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.1</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?t=86199" rel="nofollow">http://forum.springsource.org/showthread.php?t=86199</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398103974" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11672" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11672/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11672">#11672</a> AbstractDataBoundFormElementTag generates incorrect input name attribute when using indexed properties (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>