I have the following (note that I am using the spring convention by prefixing with underscore):
<input type="checkbox" name="speakersIds[${speaker.id}]" value="true" />
<input type="hidden" name="_speakersIds[${speaker.id}]" value="false" />
speakersIds is a map property of my model.
Map<Long, Boolean> speakersIds;
The problem is that in my controller, unchecked checkbox are not set to false.
Example:
if speakersIds[0] was checked, then speakersIds.get(0) == true
if speakersIds[0] was not checked, then speakersIds.get(0) == null. <— shouldn’t this be == false?
Why?
In case of map, the underscore convention do not seem to work.
I finally just used the same property name in the hidden input.
<input type="checkbox" name='speakersIds["${speaker.id}"]' value="True" /><input type="hidden" name='speakersIds["${speaker.id}"]' value="False" />
While testing I had to change the type of speakersIds from Map<Long, Boolean> to Map<String, Boolean> but it should work with long as map key too.