<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=mrokitka" rel="nofollow">Mike Rokitka</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5359?redirect=false" rel="nofollow">SPR-5359</a></strong> and commented</p>
<p dir="auto">HTML code generated via Spring's form tag library for checkboxes and radiobuttons is generating invalid HTML id attributes (square brackets to represent array).  This appears to work fine for the other form input types, but the HTML is incorrect for checkboxes and radiobuttons.</p>
<p dir="auto">Sample code:</p>
<hr>
<p dir="auto">&lt;c:forEach var="currentTest" items="${testForm.tests}" varStatus="itStatus"&gt;</p>
<p dir="auto">&lt;li&gt;<br>
&lt;form:checkbox path="tests[${itStatus.index}].copy"/&gt;<br>
&lt;/li&gt;<br>
&lt;/c:forEach&gt;</p>
<hr>
<p dir="auto">Generates the following HTML for the checkbox:</p>
<p dir="auto">&lt;input id="tests[0].copy1" name="tests[0].copy" type="checkbox" value="true"/&gt;&lt;input type="hidden" name="_tests[0].copy" value="on"/&gt;</p>
<p dir="auto">Changing the form:checkbox tag to a form:hidden tag renders valid HTML:</p>
<p dir="auto">&lt;input id="tests0.copy" name="tests[0].copy" type="hidden" value="false"/&gt;<br>
This appears to be related to this issue: <a href="http://jira.springframework.org/browse/SPR-2380" rel="nofollow">http://jira.springframework.org/browse/SPR-2380</a>?</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.6</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=iegoshin" rel="nofollow">Ilya</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5382?redirect=false" rel="nofollow">SPR-5382</a></strong> and commented</p>
<p dir="auto">org.springframework.web.servlet.tags.form.TagIdGenerator which is used by tags checkboxes and radiobuttons doesn't filter out [] and double-quotes from id attribute. It breaks html and javascript for map-based properties. Can be fixed like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? new Integer(currentCount.intValue() + 1) : new Integer(1));
	pageContext.setAttribute(attributeName, currentCount);
	return (StringUtils.deleteAny(name, &quot;[]\&quot;&quot;) + currentCount.intValue());
}"><pre class="notranslate"><code class="notranslate">public static String nextId(String name, PageContext pageContext) {
	String attributeName = PAGE_CONTEXT_ATTRIBUTE_PREFIX + name;
	Integer currentCount = (Integer) pageContext.getAttribute(attributeName);
	currentCount = (currentCount != null ? new Integer(currentCount.intValue() + 1) : new Integer(1));
	pageContext.setAttribute(attributeName, currentCount);
	return (StringUtils.deleteAny(name, "[]\"") + currentCount.intValue());
}
</code></pre></div>
<hr>
<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="398103128" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11537" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11537/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11537">#11537</a> Spring MVC regression: binding to indexed properties is broken</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398102921" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11506" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11506/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11506">#11506</a> form:checkbox tag creates invalid HTML id when bound to indexed property</li>
</ul>
<p dir="auto"><strong>Backported to:</strong> <a href="https://github.com/spring-projects/spring-framework/milestone/68?closed=1">3.0.1</a></p>