<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gpablo" rel="nofollow">Pablo</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7710?redirect=false" rel="nofollow">SPR-7710</a></strong> and commented</p>
<p dir="auto">In freemarker, if I use the formInput macro with an array parameter:</p>
<p dir="auto">&lt;<code class="notranslate">@spring</code>.formInput "command.values[0]"/&gt;</p>
<p dir="auto">spring generates a form with an invalid id: 'values[0]'</p>
<p dir="auto">This is related to <a href="https://jira.springframework.org/browse/SPR-2380" rel="nofollow">https://jira.springframework.org/browse/SPR-2380</a>, which was the same bug but with jsp. It is possible that the same happens with velocity.</p>
<p dir="auto">To fix it in freemarker, you can change, in spring.ftl:</p>
<p dir="auto">160c160<br>
&lt;     &lt;input type="${fieldType}" id="${status.expression}" name="${status.expression}" value="&lt;#if fieldType!="password"&gt;${stringStatusValue}&lt;/#if&gt;" ${attributes}&lt;<code class="notranslate">@closeTag</code>/&gt;<br>
—</p>
<blockquote>
<p dir="auto">&lt;input type="${fieldType}" id='${status.expression?replace("[", "<em>")?replace("]", "</em>")}' name="${status.expression}" value="&lt;#if fieldType!="password"&gt;${stringStatusValue}&lt;/#if&gt;" ${attributes}&lt;<code class="notranslate">@closeTag</code>/&gt;</p>
</blockquote>
<p dir="auto">This change replaces the [ and ] with _.</p>
<p dir="auto">I am currently using spring 2.5, so it would be nice to have it backported, if possible.</p>
<p dir="auto">thanks a lot.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.8, 2.5 RC1, 2.5 RC2, 2.5 final, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6, 3.0 M1, 3.0 M2, 3.0 M3, 3.0 M4, 3.0 RC1, 3.0 RC2, 3.0 RC3, 3.0 GA, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5</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="398114780" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13374" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13374/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13374">#13374</a> Using array syntax generates invalid id using freemarker (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=przemek.ch" rel="nofollow">Przemek Ch</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8732?redirect=false" rel="nofollow">SPR-8732</a></strong> and commented</p>
<p dir="auto">Method</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;);
}"><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>);
}</pre></div>
<p dir="auto">form AbstractDataBoundFormElementTag class doesn't work with freemarker.</p>
<p dir="auto">Example</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;@spring.formInput path=&quot;lead.additionalSalesList[1].saleResult.policyId&quot; attributes='class=&quot;policyId_1&quot;'/&gt;"><pre class="notranslate">&lt;@spring.formInput path="lead.additionalSalesList[1].saleResult.policyId" attributes='class="policyId_1"'/&gt;</pre></div>
<p dir="auto">generates</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;input id=&quot;additionalSalesList[1].saleResult.policyId&quot; class=&quot;policyId_0&quot; type=&quot;text&quot; value=&quot;&quot; name=&quot;additionalSalesList[1].saleResult.policyId&quot;&gt;"><pre class="notranslate">&lt;<span class="pl-ent">input</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>additionalSalesList[1].saleResult.policyId<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>policyId_0<span class="pl-pds">"</span></span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>text<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>additionalSalesList[1].saleResult.policyId<span class="pl-pds">"</span></span>&gt;</pre></div>
<p dir="auto">According to <a href="https://jira.springsource.org/browse/SPR-2380" rel="nofollow">https://jira.springsource.org/browse/SPR-2380</a> the code above should generate id="additionalSalesList1.saleResult.policyId"</p>
<p dir="auto">[] in ID is not a valid HTML so libraries like jQuery cant handle such elements</p>
<p dir="auto">Tricks like this <code class="notranslate">$(":input[name='additionalSalesList[1]\\.saleResult\\.policyId']")</code> are needed now to select such items using jQuery.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.6</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="398108500" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12366" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12366/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12366">#12366</a> Using array syntax generates invalid id in freemarker (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398091064" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9845" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9845/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9845">#9845</a> Binding in Velocity templates using EL accessors ([, ]) for collections produces non xhtml strict compliant output</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/ba03d5b0c7d7211f910c5bc48c0895fe86614104/hovercard" href="https://github.com/spring-projects/spring-framework/commit/ba03d5b0c7d7211f910c5bc48c0895fe86614104"><tt>ba03d5b</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/e7e74c83d84dcd552d0e75458c91bc920e64d4d4/hovercard" href="https://github.com/spring-projects/spring-framework/commit/e7e74c83d84dcd552d0e75458c91bc920e64d4d4"><tt>e7e74c8</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/a9f42061510e5015965a6a680d866db519b5356d/hovercard" href="https://github.com/spring-projects/spring-framework/commit/a9f42061510e5015965a6a680d866db519b5356d"><tt>a9f4206</tt></a></p>
<p dir="auto">2 votes, 5 watchers</p>