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

Problem with rerending a specific page block section

I'm having a problem when i try to rerender a specific pageblock section as opposed to the entire page. Here's a snippet of the code:


The idea is that I only want a specific section to show, when certain criteria are met. So on the onchange event, i want to rerender that specific pageblock section. But it's not working correctly. It works if i try to rerender the entire page. But i can't do that because then i loose all the values that have been input into all the fields on the form. Any ideas on what i'm doing wrong?



<apex:page standardController="case" sidebar="false"> <apex:sectionHeader title="Sponsor: {!$User.FirstName} {!$User.LastName}" subtitle="New Badge Request" /> <apex:form > <apex:pageBlock title="Edit Case" id="thePageBlock" mode="edit"> <apex:actionRegion > <apex:pageBlockSection title="Initiation Information" columns="1" collapsible="false" > <apex:pageBlockSectionItem > <apex:outputLabel value="Is Initiation Required for this Applicant?"/> <apex:outputPanel > <apex:inputField value="{!case.E_Initiation_Required__c}" required="true"> <apex:actionSupport event="onchange" rerender="something" status="status2"/> </apex:inputField> <apex:actionStatus startText="Updating required fields..." id="status2"/> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageblocksection> </apex:actionRegion> <apex:pageBlockSection id="something" rendered="{!case.E_Initiation_Required__c == 'Yes'}"> <apex:inputField value="{!case.Requesting_Organization__c}" /> <apex:inputField value="{!case.Sub_Agency__c}" /> <apex:inputField value="{!case.Region_Num__c}" /> <apex:inputfield value="{!case.Central_Office__c}" /> <apex:inputField value="{!case.Applicant_s_Supervisors_Name__c}" /> <apex:inputField value="{!case.Applicant_s_Supervisor_Phone_Number__c}" /> </apex:pageBlockSection>







Best Answer chosen by Admin (Salesforce Developers) 

and here's the answer to this one.


If the component with the id you're referencing is not on the page, you won't be able to bring it back. 

All Answers


and here's the answer to this one.


If the component with the id you're referencing is not on the page, you won't be able to bring it back. 

This was selected as the best answer
Thanks Jill, wrapping the pageblocksection in an output panel worked !!!

Hey Jill


I realize the person who asked about this got their solution, but I'm looking at the example, and I don't see the problem. I saw the issue with the outputText in the solution you referenced, but in this example, it appears to me that the pageBlocksection with the id="something" is on the page, at least from the code. 


Why did the pageblocksection need to be wrapped in an additional outputPanel to appear on the page?? 

I'm sure I will run into a similar situation so some additional clarity would be helpful. My thinking is that a pageBlockSection will appear and rerender inside of a pageBlock when called by an action outside of the pageBlock. Not true?





The block section has a 'rendered' attribute, so if the block section initially is not on the page at all (rendered resolves to false), then there is no block section to re-render. My guess is that's the original problem the poster ran into. Wrapping the block section in something that is always there solves the problem.


Right.  The point is you have an outputPanel with an id attribute, and a pageBlockSection inside of that with a rendered attribute.


That way you always rerender the outputPanel by specifying the id, and it will go through and render all of its children again.  Since the outputPanel never disappears from the page, you can always reference it on your page.  Without the outputPanel you wind up with the situation gliu mentioned.