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
sylar20sylar20 

Rendering a page block section based on conditions

I am trying to render a page block section dynamically based on two conditions , on Case Object. These two conditions are picklists. I am using the standard case controller. I haven't created any custom class controller for this.

 

I am not able to do so.. Kindly Help..

 

Following is my Custom Case VF page

<apex:page standardController="Case">
    <apex:sectionHeader title="{!$ObjectType.Case.label} Edit" subtitle="{!Case.Casenumber}"/>
    <apex:form >
    <apex:pageBlock title="{!$ObjectType.Case.label} Edit" mode="edit">
    
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>   
        </apex:pageBlockButtons>
        <apex:actionRegion >
        <apex:pageBlockSection showHeader="true" title="Case Information" columns="2">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Case Owner"/>
                <apex:outputText value="{!Case.Owner.Name}"/>
            </apex:pageBlockSectionItem>
            <apex:inputField required="true" value="{!Case.Status}"/>
            <apex:inputField value="{!Case.Priority}"/>
            <apex:inputField required="true" value="{!Case.ContactId}"/>
            <apex:inputField required="true" value="{!Case.AccountId}"/>
            <apex:inputField required="true" value="{!Case.Origin}"/>
            <apex:inputField value="{!Case.Department__c}"/>
                            
                        <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Case Reason"/>
                        <apex:outputPanel >
                            <apex:inputField value="{!Case.Case_Reason2__c}">
                                <apex:actionSupport event="onchange" rerender="thePageBlock" status="Status"/>
                            </apex:inputField>
                            <apex:actionStatus startText="Loading Client Information Block..." id="Status"/>
                        </apex:outputPanel>
 </apex:pageBlockSectionItem>

            
            <apex:inputField value="{!Case.Account_Set_Up__c}"/>
            <apex:inputField required="true" value="{!Case.FCR__c}"/>
            <apex:inputField value="{!Case.User_Set_up__c}"/>
            <apex:inputField required="true" value="{!Case.Complaint__c}"/>
            <apex:inputField value="{!Case.EChain_Contact__c}"/>
            <apex:inputField required="true" value="{!Case.Route_to_Helpdesk__c}"/>
            <apex:inputField value="{!Case.Escalated_to_Ops_QA__c}"/>
            <apex:inputField value="{!Case.Source__c}"/>
            <apex:inputField value="{!Case.CSE_Case_Number_For_Ops_QA_only__c}"/>
            <apex:inputField value="{!Case.Escalation_Assist_Log__c}"/>
            <apex:inputField value="{!Case.CSR__c}"/>
        </apex:pageBlockSection>
        </apex:actionRegion>
        <apex:pageBlockSection showHeader="true" title="Description Information" columns="1">
            <apex:inputField value="{!Case.Subject}"/>
            <apex:inputField value="{!Case.Description}"/>
            <apex:inputField value="{!Case.Action_Taken__c}"/>
        </apex:pageBlockSection>
        
        <apex:pageBlockSection showHeader="true" title="Dispute Information" columns="2">
            <apex:inputField value="{!Case.Dispute_Investigator__c}"/>
            <apex:inputField value="{!Case.Dispute_Jurisdiction__c}"/>
            <apex:inputField value="{!Case.Dispute_Resolution__c}"/>
            <apex:inputField value="{!Case.Dispute_re__c}"/>
            <apex:inputField value="{!Case.Business_Line__c}"/>
            <apex:inputField value="{!Case.Reason_Detail__c}"/>
        </apex:pageBlockSection>
   <apex:actionRegion >
   <apex:outputPanel id="thePageBlock" rendered="{IF(!Case.Department__c == 'Criminal' && !Case.Case_Reason2__c == 'Applicant Dispute', true, false)}">
   
   
 <apex:pageBlockSection showHeader="true"  title="Client Facing Criminal Dispute Information" columns="2" >
            <apex:inputField value="{!Case.Dispute_initiated_by__c}"/>
            <apex:inputField value="{!Case.Applicant_Name__c}"/>
            <apex:inputField value="{!Case.Client_Name__c}"/>
            <apex:inputField value="{!Case.Jurisdiction_1__c}"/>
            <apex:inputField value="{!Case.Order__c}"/>
            <apex:inputField value="{!Case.Jurisdiction_2_Optional__c}"/>
            <apex:inputField value="{!Case.Client_Email_Address__c}"/>
            <apex:inputField value="{!Case.Jurisdiction_3_Optional__c}"/>
            <apex:inputField value="{!Case.Client_Email_Address_Optional__c}"/>
            <apex:inputField value="{!Case.Applicant_Dispute_Notification__c}"/>
            <apex:inputField value="{!Case.Client_Email_Address_Optional2__c}"/>
            <apex:inputField value="{!Case.Applicant_Dispute_Resolve_Favour__c}"/>
            <apex:inputField value="{!Case.Client_Email_Address_Optional3__c}"/>
            <apex:inputField value="{!Case.Applicant_Dispute_Resolve_Not_Favour__c}"/>
        </apex:pageBlockSection>
       </apex:outputPanel>
       </apex:actionRegion>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney
//depending on whether you want the comparisons to be equality or inequality, use == or !=. I've assumed equality below.

<apex:outputPanel id="thePageBlock" rendered="{!(Case.Department__c == 'Criminal' && Case.Case_Reason2__c == 'Applicant Dispute')}">


All Answers

Ritesh AswaneyRitesh Aswaney
//depending on whether you want the comparisons to be equality or inequality, use == or !=. I've assumed equality below.

<apex:outputPanel id="thePageBlock" rendered="{!(Case.Department__c == 'Criminal' && Case.Case_Reason2__c == 'Applicant Dispute')}">


This was selected as the best answer
jwetzlerjwetzler

You can't rerender something that's not there.  There are many many posts about this on the forums.  Your outputPanel is conditionally rendered, which means that at times it could not appear on your page.  If it doesn't appear on your page, it will not be able to be re-evaluated for rerendering.

 

If you're expecting an element to disappear and reappear on your page, then you always need to be rerendering a component that surrounds the element with the rendered attribute.

 

Also look at what Ritesh posted, because your syntax is wrong (you need to move your '!' operator to the correct spot, as in his example).

bob_buzzardbob_buzzard

WRT to Jill's comment above, here's a blog post that I wrote the last time (but not the first!) that this caught me out:

 

http://bobbuzzard.blogspot.com/2011/02/visualforce-re-rendering-woes.html

 

 

Deepika GulatiDeepika Gulati

HI,

 

Rendering a Page Block allotes some space to it on a Page.

 

If  there two PageBlock sections, only one of them has to be displayed based on the Boolean set in the Controller class.

I have used rendered property but if Second Block section is displayed it leaves space in between for the First Page Block Section.

 

i dnt want that space.

 

Can you Please Help me.

 

Thanks.

bob_buzzardbob_buzzard

Have you set the layout property on the outputpanel?  I think it defaults to block which will insert a div.  if you change it to none does that help?