1

I have a VF page where I am trying to set up a rerender of 1 field when a certain set of values is selected in another field (picklist). I can do the rerender on the entire pageBlockSection, but I would like to only rerender the 2 elements involved, which are contained in 2 separate pageBlockSectionItems. Does anyone know how I can accomplish this? Below are the 2 sections I would like to rerender.

<apex:pageBlock mode="edit" title="Required Fields on Account">
     <apex:pageBlockSection columns="1">
        <apex:pageBlockSectionItem id="Vertical">
              <apex:outputLabel value="Buyer Segment"/>
        <apex:actionRegion >
              <apex:inputField value="{!Account.Buyer_Segment__c}">
                   <apex:actionSupport event="onchange" reRender="Vertical"/>
              </apex:inputField>
        </apex:actionRegion >
        </apex:pageBlockSectionItem>

        <apex:pageBlockSectionItem rendered="{!IF(Account.Buyer_Segment__c = $Label.Acct_BuySeg1,TRUE,FALSE)}">
             <apex:outputLabel value="Vertical"/>
             <apex:inputField value="{!Account.Industry}" />
        </apex:pageBlockSectionItem>

...Other pageBlockSectionItems here...

    </apex:pageBlockSection>
<apex:pageBlock>
  • 1
    You can add id attribute to the second pageBlockSectionItem for example id="secondItem" and then use rerender with separated by comma ids like this: rerender="vertical, secondItem" – Paul Boiko Nov 17 '15 at 20:49
  • Thanks Paul, but that does not seem to do anything. – J. Neilan Nov 17 '15 at 21:01
3

You need to rerender something that surrounds the item that needs to appear and disappear.

In your case, since there are two children of your page block section, I would rerender that, rather than do a whole bunch of individual items within. Like this:

<apex:pageBlock mode="edit" title="Required Fields on Account">

  <!--tell VF to rerender this parent UI section
  this will rerender all children as well, instead of bits and pieces here and there-->

  <apex:pageBlockSection id="areaToReRender" columns="1">
    <apex:pageBlockSectionItem>
      <apex:outputLabel value="Buyer Segment"/>
      <apex:actionRegion >
        <apex:inputField value="{!Account.Buyer_Segment__c}">

          <!--you already get how this works, but for clarity to others who read
          this, "reRender" identifies the component ID to rebuild cascading to all children-->

          <apex:actionSupport event="onchange" reRender="areaToReRender"/>
        </apex:inputField>
      </apex:actionRegion >
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem rendered="{!IF(Account.Buyer_Segment__c = $Label.Acct_BuySeg1,TRUE,FALSE)}">
      <apex:outputLabel value="Vertical"/>
      <apex:inputField value="{!Account.Industry}" />
    </apex:pageBlockSectionItem>

...Other pageBlockSectionItems here...

</apex:pageBlockSection>

I've not tested this, and it has been a while since I used this, but when I did, if an item was ever conditionally rendered, I often had trouble unless I pointed the rerender on a component at least one level above the conditional component. And here, since you clearly want the label to refresh, too, might as well just do a parent and get the refresh to include both children.

  • Thanks Peter. I did have it rerender the entire pageBlockSection originally, but what was happening was if there were other fields that were required and not completed, it was then ignoring the selections in my Buyer Segment field. I was hoping to be able to just rerender the 2 pageBlockSectionItems I need to. I did try using an outputPanel, but that removes all the standard formatting of the SectionItems. Any ideas on another way? – J. Neilan Nov 18 '15 at 15:21
  • 1
    apex:actionRegion should see to this...by surrounding only the Account.Buyer_Segment__c field with this tag, only this value should be processed by the server request. That is, unless there is some other action region, or there is some other logic somewhere triggering a save of the record. Here is a gist that I have working in a sandbox to show this: gist.github.com/pchittum/6d47483a0b2f82e735f5 – pchittum Nov 19 '15 at 10:58
  • Peter, thanks! The problem is that still rerenders the entire pageBlock. I can definitely do that, but the issue I run into is that some other fields are mandatory. If they click the checkbox or picklist that is the subject of the actionRegion before completing the mandatory fields, the mandatory logic takes precedence and then they have to essentially undo and re-do the actionRegion. I was hoping to just be able to rerender a pageBlockSection or pageBlockSectionItem. So far I have had no luck with either, while still maintaining the standard SFDC formatting. – J. Neilan Nov 19 '15 at 17:51
  • I'm clearly having trouble visualizing what you mean. Required fields should be ignored with actionRegion in the way you have it. – pchittum Nov 19 '15 at 18:08
  • Essentially, I put the actionRegion around a checkbox input field contained in a pageBlockSectionItem tab. I have another lookup field contained in another pageBlockSectionItem tab a few rows down in my layout. I only want those 2 sectionItems to rerender, however, when I add an Id element to the pageBlockSectionItem, it's just ignored. It's very frustrating. – J. Neilan Nov 19 '15 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.