I want to iterate a HashMap in javascript using jstl. is it possible to do like this?
function checkSelection(group,tvalue){
alert(group);
alert(tvalue);
&l
It is not possible because JSP is executed first at the server side, then the JavaScript gets executed at the client side.
You can still use the c:forEach
to loop through the ${configuredGroupMap}
, but you cannot do the comparison across groupMap.key
and group
directly.
Instead, a solution in this case is to assign the server-side groupMap.key
to a client-side variable in javascript first. Then use javascript for the if check, instead of c:if
.
I've modified your example to below
function checkSelection(group,tvalue){
alert(group);
alert(tvalue);
alert(" ");
var groupKey = " ";
if (groupKey == group){
alert(" ");
var groupValue = " ";
if (groupValue == tvalue){
alert("both are equal");
}
}
}