function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nununinununi 

Dynamically render page sections based on checkbox values

Hello Evryone,
I am trying to render two sections based on two checkbox values. If Export is TRUE then show Sample1 and in Import is TRUE then show Sample 2.

VF Page:
<apex:page standardcontroller="Opportunity" tabStyle="Opportunity" extensions="OppExt">
  <apex:form >
      <apex:pageBlock title="Opportunity Edit">
       <apex:pageBlockButtons >
        <apex:commandButton action="{!getcontinue}" value="continue"/>
        <apex:commandButton action="{!Cancel}" value="Cancel"/>
       </apex:pageBlockButtons>
       
       <apex:pageBlockSection id="block" title="Service Type Field Information" columns="2" >
             <apex:inputField value="{!Opportunity.Export_ck__c}">
                  <apex:actionsupport event="onclick" rerender="Sample1" status="AjaxStatus1"/>
             </apex:inputField>
             <apex:inputField value="{!Opportunity.Import_ck__c}">
                  <apex:actionsupport event="onclick" rerender="Sample2" status="AjaxStatus2"/>
             </apex:inputField>
         
       </apex:pageBlockSection> 
 
       <apex:pageBlockSection title="Opportunity Information" columns="2">
            <apex:outputField title="Opportunity Owner" value="{!Opportunity.OwnerId}"/>
            <apex:inputField required="true" value="{!Opportunity.Type}"/>
            <apex:inputField value="{!Opportunity.Name}"/>
            <apex:inputField value="{!Opportunity.LeadSource}"/>
            <apex:inputField value="{!Opportunity.AccountId}"/>
            <apex:inputField value="{!Opportunity.CloseDate}"/>
            <apex:inputField required="true" value="{!Opportunity.Priority__c}"/>
            <apex:inputField required="true" value="{!Opportunity.Lead_Source_Details_del__c}"/>
            <apex:inputField value="{!Opportunity.Contact__c}"/>
            <apex:inputField value="{!Opportunity.Mobile__c}"/>
        </apex:pageBlockSection>
        
        <apex:outputpanel id="Sample1">
        <apex:actionStatus id="AjaxStatus1">
               <apex:facet name="stop"> 
                 <apex:pageBlockSection title="Additional Information" columns="2" rendered="{!IF(Opportunity.Export_ck__c == true, true, false)}">
                    <apex:inputField required="true" value="{!Opportunity.NextStep}"/>
                    <apex:inputField required="true" value="{!Opportunity.Description}" />
                    <apex:inputField required="true" value="{!Opportunity.Followup_DateTime__c}"/>
                 </apex:pageBlockSection> 
               </apex:facet> 
        </apex:actionStatus> 
        </apex:outputpanel>  
        
        <apex:outputpanel id="Sample2">
        <apex:actionStatus id="AjaxStatus2">
              <apex:facet name="stop">
                <apex:pageBlockSection title="Other Information" columns="2" rendered="{!IF(Opportunity.Import_ck__c == true, true, false)}">
                    <apex:inputField required="false" value="{!Opportunity.Probability}" />
                    <apex:inputField value="{!Opportunity.Test_Month_Closed_Today_s_Month__c}"/>
                </apex:pageBlockSection> 
              </apex:facet>
        </apex:actionStatus> 
        </apex:outputpanel> 
         
      </apex:pageBlock>
  </apex:form>
</apex:page>

Controller:
public with sharing class OppExt {

    Public Opportunity opp {get;set;}
    
    Public Boolean Export_ck {get;set;}
    Public Boolean Import_ck {get;set;}
    
    Private ApexPages.StandardController sController;
    
    public OppExt(ApexPages.StandardController controller) 
    {
        this.opp=(Opportunity)Controller.getRecord();
        sController=controller;
        
    }
    Id DomesticRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Domestic').getRecordTypeId();
    public PageReference getcontinue()
    {
    
      sController.save();
      
     PageReference pr = new PageReference('/006/e?retURL=%2F006%2Fo&RecordType='+DomesticRecordTypeId+'&ent=Opportunity');  
     pr.setRedirect(true);
     return pr;
    }

}


Best Answer chosen by nununi
nitesh gadkarinitesh gadkari
Hi ,
 This Simple code may help you to achieve your goal.All the best.

//##VisualForce code

<apex:page controller="testactionsupportcontroller">
  <apex:form >
    <apex:pageBlock >
       <apex:commandButton value="Process"/>
       <apex:inputCheckbox value="{!output1}">Export</apex:inputCheckbox>
       <apex:inputCheckbox value="{!output2}">Import</apex:inputCheckbox>
      <apex:outputPanel id="out1" rendered="{!output1}">
        <p>hello this is sfdc</p>
      </apex:outputPanel>
      <apex:outputPanel id="out2" rendered="{!output2}">
        <p>HEllo this is nitesh</p>
      </apex:outputPanel>
    </apex:pageBlock>
  </apex:form>
</apex:page>

//##controller code

public with sharing class testactionsupportcontroller {

    public boolean output2 { get; set; }

    public boolean output1 { get; set; }
    
    public testactionsupportcontroller(){
    output1=false; 
    output2=false; 
     
    } 
    
}

Regards
Nitesh