In my Spring MVC project I am getting the one Boolean variable as a model attribute from the controller in my JSP view. based on the Boolean variable's value I have to execute the Js code. So I am comparing the value in the if statement. but it is not giving me the correct output:
The code is something like this:
In spring controller the Boolean variable is:
boolean isAdmin;
which is recieved by the JSP view and I can access it as follows:
$(isAdmin)
In my JSP view I am doing as follows:
<script>
alert('${isAdmin}') // which gives the correct value .i.e : true / false
if('${isAdmin}'){
// some code
}
</script>
So in the above if statement if the value of the isAdmin is false than it should not be execute if block but it does executed even the value is true.
I also compared the value of the Boolean variable as follow:
if('${isAdmin}' == true )
if('${isAdmin}' === true)
But these both are also not working.
So correct me where I am doing the wrong? and what is the correct comparison method for this?
'${isAdmin}' === 'true'.truebut'true', which is text.