New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form:checkbox tag creates invalid HTML id when bound to indexed property [SPR-6840] #11506

spring-issuemaster opened this Issue Feb 14, 2010 · 1 comment


None yet
2 participants
Copy link

spring-issuemaster commented Feb 14, 2010

Hans Desmet opened SPR-6840 and commented

When the tag form:checkbox is bound to an indexed property, it creates an HTML id which contains the characters [ and ]

  • These characters are not allowed in an id.
  • The form:label tag that is bound tot the same indexed property doesn't contain [ and ] in the for attribute
    and therefore is not correctly coupled to the corresponding checkbox.

A checkbox generated in the example:
<input id="countries[Belgium]1" name="countries[Belgium]" type="checkbox" value="true" checked="checked"/>

The corresponding label:
<label for="countriesBelgium">Belgium</label>

The class that acts as command object:

package org.example.entities;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class Continent {
// key = name of country
// Boolean= bordered by the sea
private Map<String, Boolean> countries = new LinkedHashMap<String, Boolean>();

public void setCountries(Map<String, Boolean> countries) {
this.countries = countries;

public void addCountry(String name, boolean borderedByTheSea) {
countries.put(name, borderedByTheSea);

public Map<String, Boolean> getCountries() {
return Collections.unmodifiableMap(countries);


The Controller class:

package org.example.web;

import org.example.entities.Continent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

public class ContinentController {
@RequestMapping(value = "/continent.htm", method = RequestMethod.GET)
public String continentForm(Model model) {
Continent continent=new Continent();
continent.addCountry("Belgium", true);
continent.addCountry("Switzerland", false);
return "continent.jsp";

@RequestMapping(value = "/person.htm", method = RequestMethod.POST)
public void personForm(@ModelAttribute Continent continent) {


<?xml version="1.0" encoding="UTF-8"?>

<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
<%@taglib prefix="c" uri=""%>
<%@taglib prefix="form" uri=""%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="nl" lang="nl">
<title>Person example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form:form commandName="continent" method="get">
<c:forEach items="${continent.countries}" var="entry">
<form:checkbox path="countries[${entry.key}]" />
<form:label path="countries[${entry.key}]">${entry.key}</form:label>
<div><input type="submit" /></div>

Affects: 3.0 GA

Issue Links:

  • #11537 Spring MVC regression: binding to indexed properties is broken
  • #10055 org.springframework.web.servlet.tags.form.TagIdGenerator doesn't remove characters [] and double-quotes

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Feb 14, 2010

Juergen Hoeller commented

Indeed, CheckboxTag should delete such brackets just like LabelTag does. Fixed for 3.0.1!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment