6

I want to render the second pageBlockSectionItem when the stage of the picklist named "StageName" is "Lead Qualified"

My tags:

<apex:page standardController="Opportunity" extensions="GeoGradeSelectionController">

  <apex:sectionHeader title="Lead" subtitle="{!Opportunity.Name}"/>

  <apex:form >
    <apex:pageBlock title="Lead Edit" id="pb" mode="edit">

      <apex:pageBlockSection title="General Information">
      <!-- FIRST PICKLIST WITH OPTION Lead Qualified -->
        <apex:inputField value="{!Opportunity.StageName}">
           <apex:actionSupport event="onchange" reRender="LeadQualified"/>
        </apex:inputField> 

        <!-- SECOND PICKLIST TO RENDER ID STAGENAME="Lead Qualified" -->
       <apex:pageBlockSectionItem rendered="{!opportunity.stageName == 'Lead Qualified'}" id="LeadQualified">
           <apex:outputLabel value="Lead Qualified RecordType"/>
            <apex:outputPanel styleClass="requiredInput" layout="block" id="pwPanel"> 
            <apex:outputPanel styleClass="requiredBlock"/> 
            <apex:selectList value="{!Opportunity.LeadQualifiedRecordType__c}" size="1" required="true" multiselect="false">
                  <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
                  <apex:selectOption itemValue="Proactive Selling Opportunity" itemLabel="Proactive Selling"/>  
            </apex:selectList> 
            </apex:outputPanel>
        </apex:pageBlockSectionItem>  
      </apex:pageBlockSection>

    </apex:pageBlock>
  </apex:form>
</apex:page>

The rerender for component with id="LeadQualified" is not working. Do you know why?

UPDATE:second version according to Ralph´s answer:

<apex:page standardController="Opportunity" extensions="GeoGradeSelectionController">

  <apex:sectionHeader title="Lead" subtitle="{!Opportunity.Name}"/>

  <apex:form >
    <apex:pageBlock title="Lead Edit" id="pb" mode="edit">

      <apex:pageBlockSection title="General Information">
      <!-- FIRST PICKLIST WITH OPTION Lead Qualified -->
        <apex:inputField value="{!Opportunity.StageName}">
           <apex:actionSupport event="onchange" reRender="pb"/>
        </apex:inputField> 

        <!-- SECOND PICKLIST TO RENDER ID STAGENAME="Lead Qualified" -->

         <apex:inputField value="{!Opportunity.Name}"/>
         <apex:inputField value="{!Opportunity.Probability}"/>
         <apex:inputField value="{!Opportunity.AccountId}" required="true"/> 
            <apex:selectList value="{!Opportunity.LeadQualifiedRecordType__c}" size="1" required="true" multiselect="false" rendered="{!opportunity.stageName == 'Lead Qualified'}">
                  <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
                  <apex:selectOption itemValue="Proactive Selling Opportunity" itemLabel="Proactive Selling"/>  
            </apex:selectList> 

      </apex:pageBlockSection>

    </apex:pageBlock>
  </apex:form>
</apex:page>

It's still not working, please help me again.

UPDATE 2: solution according Nick.

<apex:page standardController="Opportunity" extensions="GeoGradeSelectionController">
<apex:sectionHeader title="Lead" subtitle="{!Opportunity.Name}"/>

  <apex:form >
  <apex:pageBlock title="Lead Edit" id="pb" mode="edit">

  <apex:pageBlockSection title="General Information">
    <!-- FIRST PICKLIST WITH OPTION Lead Qualified -->
    <apex:inputField value="{!Opportunity.StageName}">
       <apex:actionSupport event="onchange" reRender="LeadQualified"/>
    </apex:inputField> 

    <!-- SECOND PICKLIST TO RENDER ID STAGENAME="Lead Qualified" -->
    <apex:outputPanel id="LeadQualified">
    <apex:pageBlockSectionItem rendered="{!opportunity.stageName == 'Lead Qualified'}" >
       <apex:outputLabel value="Lead Qualified RecordType"/>
        <apex:outputPanel styleClass="requiredInput" layout="block" id="pwPanel"> 
        <apex:outputPanel styleClass="requiredBlock"/> 
        <apex:selectList value="{!Opportunity.LeadQualifiedRecordType__c}" size="1" required="true" multiselect="false">
              <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
              <apex:selectOption itemValue="Proactive Selling Opportunity" itemLabel="Proactive Selling"/>  
        </apex:selectList> 
        </apex:outputPanel>
    </apex:pageBlockSectionItem>
   </apex:outputPanel>
  </apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

It´s working but it is giving wrong style to the field "LeadQualifiedRecordType": enter image description here

8

You've fallen into a tricky gotcha with re-rendering. When the re-render is processed, only the children of the re-rendered component or re-processed. Hence the your {!opportunity.stageName === 'Lead Qualified'} statement isn't re-evaluated and the section isn't shown.

The solution is to re-render the parent of the section having the conditional changed. Looking at your page a good candidate would be to render the pageblock with id pb.

  • Thanks a lot Ralph! I have updated my question with the version of my code according your solution. It´s still not working. Please could you have a look again? Thanks again. – Enry Jul 10 '14 at 6:43
  • @Enry if you're having a different issue, please post a separate question. The usefulness of your question for future users is diminished if you have multiple followups, and you'll get more rep with multiple questions. – Ralph Callaway Jul 10 '14 at 23:55
2

In addition to Ralph's answer, through trial and error I found that rerendering needed to be done on an outputPanel rather than other elements. It was a solution that worked for me, not sure if it will work across the board, but worth a try nonetheless.

Try wrapping the pageBlockSectionItem in an outputPanel.

i.e.

<apex:pageBlock title="Lead Edit" id="pb" mode="edit">

  <apex:pageBlockSection title="General Information">
  <!-- FIRST PICKLIST WITH OPTION Lead Qualified -->
    <apex:inputField value="{!Opportunity.StageName}">
       <apex:actionSupport event="onchange" reRender="LeadQualified"/>
    </apex:inputField> 

    <!-- SECOND PICKLIST TO RENDER ID STAGENAME="Lead Qualified" -->
    <apex:outputPanel id="LeadQualified">
   <apex:pageBlockSectionItem rendered="{!opportunity.stageName == 'Lead Qualified'}" >
       <apex:outputLabel value="Lead Qualified RecordType"/>
        <apex:outputPanel styleClass="requiredInput" layout="block" id="pwPanel"> 
        <apex:outputPanel styleClass="requiredBlock"/> 
        <apex:selectList value="{!Opportunity.LeadQualifiedRecordType__c}" size="1" required="true" multiselect="false">
              <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
              <apex:selectOption itemValue="Proactive Selling Opportunity" itemLabel="Proactive Selling"/>  
        </apex:selectList> 
        </apex:outputPanel>
    </apex:pageBlockSectionItem>
   </apex:outputPanel>
  </apex:pageBlockSection>

</apex:pageBlock>

Note: I moved the id="LeadQualified" from the pageBlockSectionItem to the outputPanel.

  • Thanks a lot for your inputs Nick! It´s working the rerender now but it´s giving wrong style to the field. I´ve updated my question, please could you give a look? – Enry Jul 10 '14 at 7:22
  • Yep, that'll work, the only thing that matters for the re-render to re-evaluate a render attribute is that it's a parent of the element with the render attribute. But I'm guessing the output panel is what's breaking the styling since you want the pageblocksectionitem to be a child of a pageblocksection not an outputpanel – Ralph Callaway Jul 10 '14 at 23:57
  • Hi Ralf, i guess is the same question. Nick´s solution is not working, like you said i want to rerender a pageblocksectionitem or a pageblocksection keeping the style. Just let me know if i m wrong. Thanks a lot for your support. – Enry Jul 11 '14 at 6:58
0

This is the solution I used: re-render the entire pageBlock ("pb") instead of trying to re-render just the one inputField.

<apex:pageBlock title="Lead Edit" id="pb" mode="edit">
  <apex:pageBlockSection title="General Information">
    <apex:pageBlockSectionItem>
      <apex:outputLabel value="{!$ObjectType.Opportunity.fields.StageName.label}" />
      <apex:actionRegion>
        <apex:inputField value="{!Opportunity.StageName}">
          <apex:actionSupport event="onchange" reRender="pb" />
        </apex:inputField>
      </apex:actionRegion>
    </apex:pageBlockSectionItem>

    <apex:pageBlockSectionItem rendered="{!opportunity.stageName == 'Lead Qualified'}">
      <apex:outputLabel value="Lead Qualified RecordType" />
      <apex:outputPanel styleClass="requiredInput" layout="block" id="pwPanel">
        <apex:selectList value="{!Opportunity.LeadQualifiedRecordType__c}" size="1" required="true" multiselect="false">
          <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity" />
          <apex:selectOption itemValue="Proactive Selling Opportunity" itemLabel="Proactive Selling" />
        </apex:selectList>
      </apex:outputPanel>
    </apex:pageBlockSectionItem>
  </apex:pageBlockSection>
</apex:pageBlock>

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.