Search code examples
freemarker

FreeMarker if statement comparing two values


I'm trying to compare two values

<#if user.cellPhone != changedUser.cellPhon>
    <br><span class="changes">*${changedUser.cellPhone}</span></#if>

I'm getting an error

freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:==> changeUser

Tip:

If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??


Solution

  • Add null check to condition changedUser??:

      <#if changedUser?? && user.cellPhone != changedUser.cellPhon>