2

I have an apex element which relies on the output of two Boolean methods to be rendered.

At the moment, both methods are evaluating to true, yet the apex element is not rendering. If I reverse one of the methods to evaluate to false, the element renders.

So the following DOES NOT render:

<apex:outputLink rendered="{!isTrue && !isTrue}"> //true && true

</apex:outputLink>

But this DOES render:

<apex:outputLink rendered="{!isTrue && ! !isTrue}"> //true && false

</apex:outputLink> 

I'm checking that the methods really are returning what I'm expecting them to by outputting them into the console.

console.log('{!isTrue}'); //true
console.log('{! !isTrue}'); //false

Am I using the rendered attribute incorrectly?

Can anyone spot what's wrong here?

9

{!} is merge syntax

Adding parentheses may help visualize what is happening in your evaluations.

true and not true == false

<apex:outputLink rendered="{! (isTrue && !isTrue) }"> 

true and not not true (true to false and then back to true) == true

<apex:outputLink rendered="{! (isTrue && !!isTrue) }"> 
| improve this answer | |
  • Ah! Cheers Mark, that cleared things up for me! – Daft Sep 3 '14 at 16:05
  • 1
    for clarity, you could use the NOT function rather than confuse yourself with the overloaded ! operator as in: <apex:outputLink rendered="{! cond1 && NOT(cond2) }"> – cropredy Sep 3 '14 at 23:06
  • @Mark Please see below code <apex:pageBlockTable value="{!cartItems}" var="item"> <apex:column value="{!cartMap[item.id]}"/> <apex:column value="{!item.Unit_Price__c}"/> <apex:column value="{! cartMap[item.id] * item.Unit_Price__c }"/> </apex:pageBlockTable> It is giving compile error - Syntax error. Extra '*' I just want to multiply both values on VF page. First value is Integer and second is decimal. Any help? – love gupta Apr 11 at 13:57
  • Ohk. Got it. Posting for the community- <apex:column headerValue="Price Per Unit" value="{!item.Unit_Price__c}"/> <apex:column headerValue="Total"> <apex:outputText value="{! cartMap[item.id] * item.Unit_Price__c }"></apex:outputText> </apex:column> </apex:pageBlockTable> – love gupta Apr 11 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.