In my if statement, I want to compare a variable, which is a JDK 1.5 enum, to an enum literal. For example:
<#if type == ProblemStatisticType.BEST_SOLUTION_CHANGED>
...
</#if>
But I get this exception:
freemarker.core.InvalidReferenceException: Expression ProblemStatisticType is undefined on line 430, column 87 in index.html.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
How can I do that?
Unfortunately, the FreeMarker language doesn't have the concept of classes... but you can do this:
<#if type.name() == "BEST_SOLUTION_CHANGED">
...
</#if>
Or if you trust the toString()
for the enum type, the .name()
part can be omitted.
If you want to compare enums you should specify a constant enum value in double quotes like:
<#if type == "BEST_SOLUTION_CHANGED">
...
</#if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With