Search code examples
freemarker

Freemarker - access static variables of an object


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!


Solution

  • 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