+ Start a Discussion

Using rendered="false" on an apex:selectOption element does not hide the option

Using the following visualforce markup, the second select option, which should not be displayed, is shown.


<apex:page> <apex:form> <apex:selectList size="1"> <apex:selectOption itemLabel="test" itemValue="test" /> <apex:selectOption itemLabel="don't show" itemValue="bad" rendered="false" /> </apex:selectList> </apex:form> </apex:page>


 Any ideas?


Does not seem to be possible to solve in VF. Guess you will have to provide this behaviour from the Controller
Message Edited by Harmpie on 04-21-2009 07:56 AM

The documentation looks like it should work.






Attribute name: rendered

Attribute type: boolean

Description: A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.

Api Version: 10.0


Can anyone at Salesforce shed some light on this? Is it a bug?


I'd like to know this as well. Did you open a case as I am about to?



I did not open a case. I must have worked around the issue as I cannot remember why I needed it. Please let me know if you get it resolved through Salesforce.



I've submitted a case and will report back.
Apparently the bug was already submitted by someone but no ETA on a fix.
I remember how I worked around this. Instead of hard coding a selectOption under the selectList and using rendered="whatever" to show/hide the options, use selectOptions and apex to figure out which options should be shown. Does this help?
Yup, that's what I ended up doing as well. It is just more work :smileytongue:
Message Edited by TehNrd on 06-09-2009 04:00 PM

YES! This has been fixed in Spring 10! Now it is a little easier to do dependent picklists. Still have to hardcode, but at least no apex is required.



<apex:page standardController="Opportunity"> <apex:form > <apex:selectList size="1" value="{!Opportunity.Name}"> <apex:selectOption itemLabel="--None--" itemValue="none" /> <apex:selectOption itemLabel="even" itemValue="even" /> <apex:selectOption itemLabel="odd" itemValue="odd" /> <apex:actionSupport event="onchange" reRender="dependent"/> </apex:selectList><br/><br/> <apex:selectList size="1" id="dependent"> <apex:selectOption itemLabel="1" itemValue="1" rendered="{!Opportunity.Name == 'odd'}"/> <apex:selectOption itemLabel="2" itemValue="2" rendered="{!Opportunity.Name == 'even'}"/> <apex:selectOption itemLabel="3" itemValue="3" rendered="{!Opportunity.Name == 'odd'}"/> <apex:selectOption itemLabel="4" itemValue="4" rendered="{!Opportunity.Name == 'even'}"/> </apex:selectList> </apex:form> </apex:page>