简体   繁体   中英

Groovy GSP <g:if>

This has been driving me crazy for hours and its probably very obvious to someone ...

Can anyone see why this is printing out even though its reporting as being false?

<g:if test="${className == 'SRep'}">
    ${className == 'SRep'}
</g:if> 

If classname==SRep then its correct. However if classname <> SRep it still prints out false? I don't understand how this can be.

If I use ?showSource=true, the if statement looks like this:

if(true && ("false")) {
  printHtmlPart(29)
}
else {
  printHtmlPart(30)
}

Anyone see anything obvious?

Thanks John

your code looks fine but im not sure what 'className' is, perhaps it's not being returned or returning wrong type etc:

i would display the output in the GSP of className just to see what it is eg add this anywhere in your GSP:

${className} //displays the value

you may also want to check the object type, in your case i think it should be string so check what you have:

${className?.class} //displays the type of object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM