I have a controller class in Spring MVC, where i am returning a HaspMap as Model attribute -
@ModelAttribute("regPrefix")
public Map<String, String> getRegPrefixesOfDepartmentforGroup(final Model model, final HttpServletRequest request) {
final Map<String, String> regPrefixOfDept = new HashMap<String, String>();
regPrefixOfDept.put(regKey, regPrefix);
return regPrefixOfDept;
}
Now in the corresponding JSP page, i am trying to access the Hashmap and store the key/value pairs of the Hasmap in a variable using JavaScript. I am trying like below but its not right. Can anyone suggest how to do that
<script>
$("#deptIdSelection").change(function()
{
var obj = document.getElementById("deptIdSelection");
var textItem = obj.options[obj.selectedIndex].text;
alert(textItem);
var mapObj = "${regPrefix}";
for(var key in mapObj)
alert(key +" ->"+ mapObj[key]);
}
);
</script>