Add single checkbox input macro for Velocity and Freemarker [SPR-4700] #9377
Currently for creating a single checkbox input we have 3 solutions:
It would be nice to has a formCheckbox macro for a single checkbox.
Indeed, it would be more flexible for:
Referenced from: commits 93e9955
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered:
mariano goyochea commented
I have this solution
<#macro formCheckbox path label attributes="">
Vladimir Kozlov commented
your solution works only for rendering (if checkbox was initially checked and after them unchecked on the webpage, new value is not posted back to controller). So, handling of FALSE is needed.
I modified your code according to http://opensource.atlassian.com/confluence/spring/display/COOK/Checkboxes+-+Dealing+with+single+checkboxes (i.e. added one line with hidden input: )
<#macro formCheckbox path attributes="">
Now it works in both cases.
Dave Syer commented
Attached patch for Freemarker only (SPR-4700-ftl.patch) with slightly different implementation and a test case. Patch is against spring-webmvc project 3.0.0 (r 1674). I'll try to do the Velocity one as well the same way.