Velocity springFormCheckboxes macro does not check preselected items correctly [SPR-10837] #15463
In Spring 3.1.4 (and possibly other releases) the springFormCheckboxes macro iterates through the $status.value variable to determine whether or not an item needs to be checked or not.
We ran into an issue with the checkboxes not properly reflecting the form backing object. Let's say the model attribute variable "command" has a variable "command.userSelections" which is of type Map<Integer, List<Integer>> and $possibleSelectionList which is of type Map<String, Integer> exposed in the model.
Iterating the command.userSelections map and using $i as the key if we use:
#springFormCheckboxes( "command.userSelections[$i]" $possibleSelectionList "" "")
We would not see any of the checkboxes as having been selected regardless of the value in command.userSelections[$i]. After further investigation it appears that the culprit is here:
The $status.value is converted to a String representation of the contents of the bound variable which in this case happens to be a List<Integer> and as such VTL is unable to traverse it in the #foreach loop above.
We used the following workaround:
By using $pathValueEval to set the variable $pathValue we're able to circumvent String conversion and get a List that can be properly iterated.
Backported to: 3.2.8
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered:
Juergen Hoeller commented
Good point. I've revised this for consistent iteration over the actualValue in our Velocity and FreeMarker macros now. We did it for FreeMarker before but not for Velocity... and we lacked exposure of an actualValue if no BindingResult is available (e.g. for a first-time rendering of a form, driven by a GET request).