You need to sign in to do that
Don't have an account?

Displaying Conditional Fields
Hi,
I am trying to construct a page where the fields displayed is dependent on the value selected from the picklist. Below is as far as I got:
<apex:page controller="statusController"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:selectList size="1" id="Status" label="Status" multiselect="false" value="{!Status}"> <apex:selectOption itemLabel="Before" itemValue="Before"/> <apex:selectOption itemLabel="During" itemValue="During"/> <apex:selectOption itemLabel="After" itemValue="After"/> </apex:selectList> <apex:actionSupport event="onchange" reRender="statusField"/> </apex:pageBlockSection> <apex:outputPanel id="statusField"> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page> public class statusController { public String Status {get; set;} }
Not sure where to specify the conditions (If statments) and how to specify what fields to display. Please help. Thank you.
You can use the rendered attribute of an inputField (or other visual component). You can furthermore use traditional formula statements. Here's an example:
You can use virtually any operator listed in Help & Training under formulas, so long as the result is a boolean value, including ISNULL, ISBLANK, CASE, OR, AND, NOT, equality and inequality operators (lesser, greater, equals, not equal, lesser than, greater than). Also of note, you can use special syntaxes that apply only to Visualforce. You should read the Visualforce Developer's Guide for more information there as well.
All Answers
You can use the rendered attribute of an inputField (or other visual component). You can furthermore use traditional formula statements. Here's an example:
You can use virtually any operator listed in Help & Training under formulas, so long as the result is a boolean value, including ISNULL, ISBLANK, CASE, OR, AND, NOT, equality and inequality operators (lesser, greater, equals, not equal, lesser than, greater than). Also of note, you can use special syntaxes that apply only to Visualforce. You should read the Visualforce Developer's Guide for more information there as well.
You need to add the output text tag and display the output and also your mistake is you need to end selectList outside the action support.
Here you go with the code: (and the controller class remains same)
<apex:page controller="statusController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList size="1" id="Status" label="Status" multiselect="false" value="{!Status}">
<apex:selectOption itemLabel="Before" itemValue="BEFORE"/>
<apex:selectOption itemLabel="During" itemValue="DURING"/>
<apex:selectOption itemLabel="After" itemValue="AFTER"/>
<apex:actionSupport event="onchange" reRender="statusField"/>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:outputPanel id="statusField">
<p> You have selected </p>
<apex:outputText value="{!Status}"></apex:outputText>
</apex:outputPanel>
</apex:form>
</apex:page>
Thanks,
JBabu.
Thank you both. They both worked. The first reply was closer to what I was looking for, but thank you.