The following examples refer to freemarker’s official documentation. In Freemarker, the default is an error if the expression is empty. So we need to nullate the expression.

  • Attribute is null
    • #{myobj.myProp! }If myProp is empty, no error is reported;
  • Return the default value
    • #{myobj.myProp!" The default value "}If myProp is empty, no error is reported and “Default” is returned. This will only work if myProp is empty, but myobj will still work if myProp is empty.
  • Objects and properties are nulled
    • #{(myobj.myProp)!" The default value "}If myobj is empty or myProp is empty, no error is reported and “default” is returned.