+ Start a Discussion
SimrinSimrin 

Rendered condition not getting evaluated for selectOptions in selectList

<apex:variable value="{!user1 !=''}"  var="op1"/>
<apex:outputText value="{!op1}"/>   //o/p True
<apex:variable value="{!user2 !=''}" var="op2"/>
<apex:outputText value="{!op2}"/>   //o/p False
 
<apex:selectList value="{!rSelected}" >
    <apex:selectOption itemValue="Select"/> 
    <apex:selectOption itemLabel="One" itemValue="One" rendered="{!op1}" />	
    <apex:selectOption itemLabel="Two" itemValue="One" rendered="{!op2}"/>
</apex:selectList>

Logically, for options, One should be displayed and Two should not be displayed, but both of them are not displayed.
Best Answer chosen by Simrin
StephenKennyStephenKenny
HI there,

The problem you face here is that both {!op1} and {!op2} are npt being set to true / false based on teh copde you have provided above. Rather than using '{!user1 !=''}', try simply setting this directyl to True or False and you will then be able to test this accordingly.


Please remember to mark this thread as solved with the answer that best helps you.

Regards
Stephen 

All Answers

SimrinSimrin
Still the same result, Both are rendered to False
StephenKennyStephenKenny
HI there,

The problem you face here is that both {!op1} and {!op2} are npt being set to true / false based on teh copde you have provided above. Rather than using '{!user1 !=''}', try simply setting this directyl to True or False and you will then be able to test this accordingly.


Please remember to mark this thread as solved with the answer that best helps you.

Regards
Stephen 
This was selected as the best answer
SimrinSimrin
If i try,
<apex:selectList value="{!rSelected}" >
    <apex:selectOption itemValue="Select"/> 
    <apex:selectOption itemLabel="One" itemValue="One" rendered="true" />	
    <apex:selectOption itemLabel="Two" itemValue="One" rendered="false}"/>
</apex:selectList>

It works correctly, but try 
 '{!user1 !=''}
or
IsBlank, IsNull, IsEmpty, fails

 
StephenKennyStephenKenny
Hi there,

Precisly my point. I believe the user1 variable is not returning the value that you expect. Add a debug statement or a simple output text to confirm what value is being stored to this variable.
SimrinSimrin
<apex:variable value="{!user1 !=''}" var="op1"/> 
<apex:outputText value="{!op1}"/> //o/p true 
<apex:variable value="{!user2 !=''}" var="op2"/>
<apex:outputText value="{!op2}"/> //o/p false

I have output it just beofore the SelectList, and it displyas correct result
StephenKennyStephenKenny
Hmm then perhaps try writing the stement like this 
rendered="{!(op1 == true)}"
SimrinSimrin

rendered="{!(op1 == true)}"
rendered="{!(op1)}"
rendered="op1"

 I tried above, but it alwyas renders false.

And, Also If i display in itemLabel="{!(op1)}" it displays true but when i use rendered="{!(op1)}", it doesnto diaplay the option.

Its very strange

SimrinSimrin

https://developer.salesforce.com/forums/ForumsMain?id=906F000000095kBIAQ

I came across this link, which says that there was bug in redered="false" , but which was fixed in Spring 10.  I use Winter 15.

Is this thing related to me, or absolutely not.

 

StephenKennyStephenKenny
Hi there,

I dont believe this bug is the cause as this will have been fixed some time ago. Hmm strange one indeed. When these scenarios occur for me I tend to start again and start simple. The first thing to understand is what value is being assigned to the User1 & User2 variables. I presume this is being set in the controller. Once you can undersatnd this, you can then use this as part of you renderded conditions

Regards,
Stephen