FreeMarker if statement comparing two values









up vote
0
down vote

favorite












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)??











share|improve this question























  • Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
    – ddekany
    Nov 9 at 23:50














up vote
0
down vote

favorite












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)??











share|improve this question























  • Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
    – ddekany
    Nov 9 at 23:50












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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)??











share|improve this question















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)??








freemarker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 13:15









user7294900

18.3k93056




18.3k93056










asked Nov 9 at 20:06









Samarland

193114




193114











  • Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
    – ddekany
    Nov 9 at 23:50
















  • Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
    – ddekany
    Nov 9 at 23:50















Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
– ddekany
Nov 9 at 23:50




Why's there no changedUser (as the error message says)? Is that intended to happen? (Why doesn't the quoted tip help?)
– ddekany
Nov 9 at 23:50












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Add null check to condition changedUser??:



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





share|improve this answer






















  • Still not working
    – Samarland
    Nov 9 at 21:38






  • 1




    Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
    – ddekany
    Nov 9 at 23:52






  • 1




    @Samarland updated according to ddekany comment
    – user7294900
    Nov 10 at 5:31










  • Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
    – Samarland
    Nov 12 at 13:14










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232629%2ffreemarker-if-statement-comparing-two-values%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Add null check to condition changedUser??:



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





share|improve this answer






















  • Still not working
    – Samarland
    Nov 9 at 21:38






  • 1




    Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
    – ddekany
    Nov 9 at 23:52






  • 1




    @Samarland updated according to ddekany comment
    – user7294900
    Nov 10 at 5:31










  • Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
    – Samarland
    Nov 12 at 13:14














up vote
1
down vote



accepted










Add null check to condition changedUser??:



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





share|improve this answer






















  • Still not working
    – Samarland
    Nov 9 at 21:38






  • 1




    Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
    – ddekany
    Nov 9 at 23:52






  • 1




    @Samarland updated according to ddekany comment
    – user7294900
    Nov 10 at 5:31










  • Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
    – Samarland
    Nov 12 at 13:14












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Add null check to condition changedUser??:



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





share|improve this answer














Add null check to condition changedUser??:



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






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 5:30

























answered Nov 9 at 20:35









user7294900

18.3k93056




18.3k93056











  • Still not working
    – Samarland
    Nov 9 at 21:38






  • 1




    Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
    – ddekany
    Nov 9 at 23:52






  • 1




    @Samarland updated according to ddekany comment
    – user7294900
    Nov 10 at 5:31










  • Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
    – Samarland
    Nov 12 at 13:14
















  • Still not working
    – Samarland
    Nov 9 at 21:38






  • 1




    Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
    – ddekany
    Nov 9 at 23:52






  • 1




    @Samarland updated according to ddekany comment
    – user7294900
    Nov 10 at 5:31










  • Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
    – Samarland
    Nov 12 at 13:14















Still not working
– Samarland
Nov 9 at 21:38




Still not working
– Samarland
Nov 9 at 21:38




1




1




Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
– ddekany
Nov 9 at 23:52




Should be changedUser?? instead of changedUser != null. FreeMarker 2 has no null.
– ddekany
Nov 9 at 23:52




1




1




@Samarland updated according to ddekany comment
– user7294900
Nov 10 at 5:31




@Samarland updated according to ddekany comment
– user7294900
Nov 10 at 5:31












Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
– Samarland
Nov 12 at 13:14




Needed it to add ?? for both condition (user.cellPhone?? != changedUser.cellPhon??)
– Samarland
Nov 12 at 13:14

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232629%2ffreemarker-if-statement-comparing-two-values%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus