I have a simple class:
public class MyClass {
public final static long MAIN = 1;
@Setter @Getter
protected int id;
}
(@Setter
@Getter
are lombok
annotations for Setter and Getter methods.)
In Freemarker template I would like to create a condition like:
<#if myClassInstance.id == myClassInstance.MAIN>
But the right hand side of the if
expression is according to FreeMarker undefined. Is there a way to do this? Thanks!
The has_content FunctionFreeMarker has built-in functions to detect for variables. The most common method of detecting for empty or null values uses the has_content function and the trim function. The has_content function is often used with another built-in FreeMarker function to detect for null values.
For example, if you create a variable called "foo" in the template, you can print its value with ${foo} . If, coincidently, there's a variable called "foo" in the data-model too, the variable created in the template will hide (not overwrite!)
The template language is not aware of Java classes. But you can expose static members through the data-model (template context). See: http://freemarker.org/docs/pgui_misc_beanwrapper.html#autoid_55
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