Play Games

Search This Blog

Tuesday, October 13, 2015

If Condition in rendered attribute in Visualforce Page

syntax : <apex:pageBlockSection title="My Content Section" columns="2" rendered="{!IF(condition,true,false)}">
Example:
Apex Class:
public class IfConditionInRendered {
    public integer count {get;set;}
    public IfConditionInRendered(ApexPages.StandardController controller) {
        count = 1;
    }
}
visualforce Page
<apex:page standardController="Account" extensions="IfConditionInRendered">
    <apex:form >
        <apex:pageBlock title="Account Section" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2" rendered="{!IF(count==1,true,false)}">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Initial Output:

Now change count value in controller  to 2.
Output :