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
sales4cesales4ce 

AJAX help: selection of Picklist value not rendering the pageblock of related object

Hi,

 

I have two objects, Opportunity and Pricing_Support__c. Both are related via lookup.

I have created a visualforce page which will then render pageblocks based on the user selection.

 

when i select the stagename, i can render a pageblock which has a field of Pricing_Support__c object.

Now, when i select a value from the above rendered field, i am unable to render another pageblock dynamically. The one in Red color below.

 

Any pointers/idea/help on this is highly appreciated.

 

FYI, the visualforce page has a standardcontroller of opportunity and a controllerextension.

 

VF Page:

<apex:page standardController="Opportunity" extensions="pricingSupport" >
      <apex:form >
          <apex:pageBlock title="Enter Opportunity Information">
              <apex:pageBlockButtons location="bottom">
                  <apex:commandButton value="Save" action="{!Save}"/>
                  <apex:commandButton value="Cancel" action="{!Cancel}" immediate="true"/>                                
              </apex:pageBlockButtons>
              <apex:PageblockSection columns="1" >
                      <apex:inputField value="{!Opportunity.Name}"/>
                     <apex:PageBlockSectionItem >
                         <apex:outputLabel value="Stage"/>
                         <apex:actionRegion >
                          <apex:inputField value="{!Opportunity.StageName}">
                          <apex:actionSupport event="onchange" reRender="ajaxrequest" status="RefreshStatus" />
                          
                          </apex:inputField>
                         </apex:actionRegion>
                      </apex:PageBlockSectionItem>
                  </apex:PageblockSection>
              <apex:outputPanel id="ajaxrequest">   
                  <apex:pageBlockSection rendered="{!Opportunity.StageName=='Prospecting'|| Opportunity.StageName!=Null}" > 
                      <apex:PageBlockSectionItem >    
                          <apex:outputLabel value="Contract Scenario"/>
                          <apex:actionRegion >                 
                              <apex:inputField value="{!priceSupport.Contract_Scenario__c}"> 
                                  <apex:actionSupport event="onchange" reRender="ajaxrequest2" status="RefreshStatus"/>
                               </apex:inputField>
                          </apex:actionRegion>  
                      </apex:PageBlockSectionItem>         
                  </apex:pageBlockSection>
              </apex:outputPanel> 
              
              <apex:outputPanel id="ajaxrequest2">   
                  <apex:pageBlockSection title="Rendered" rendered="{!priceSupport.Contract_Scenario__c=='1.Existing Contract / Contract Expansion'}" > 
                     <apex:inputField value="{!Opportunity.CloseDate}"/>
                  </apex:pageBlockSection>
              </apex:outputPanel> 
          </apex:pageBlock>
      </apex:form>
    
</apex:page>

 

Apex class(controller extension):

 

public class pricingSupport {

    Public Pricing_Support__c priceSupport {get;set;}
    public pricingSupport(ApexPages.StandardController controller) {

    }
    
    Public pageReference saveAction(){
        return Null;
    }
    
     Public pageReference cancelAction(){
        return Null;
    }

}

 

 

Thanks,

Sales4ce

Best Answer chosen by Admin (Salesforce Developers) 
sravusravu

I have two guesses where it might be going wrong:

 

1. The condiction that you are giving the rendered attribute, could you please check it once again in the sense that value "1.Existing Contract / Contract Expansion". If Contract_Scenario__c is a picklist filed then try to copy paste that value in your code as sometimes even the spaces count.

 

2.

In your extension instead of

 

 

public Pricing_Support__c  priceSupport {get;set;}

 

use

 

Pricing_Support__c priceSupport;

 

public Pricing_Support__c getpriceSupport(){

           if(priceSupport==null)

                    priceSupport = new Pricing_Support__c();

           return priceSupport;

}

 

 

try both and see if any one of them works. Most probably the first one could be the one causing the problem.

 

All Answers

sravusravu

I have two guesses where it might be going wrong:

 

1. The condiction that you are giving the rendered attribute, could you please check it once again in the sense that value "1.Existing Contract / Contract Expansion". If Contract_Scenario__c is a picklist filed then try to copy paste that value in your code as sometimes even the spaces count.

 

2.

In your extension instead of

 

 

public Pricing_Support__c  priceSupport {get;set;}

 

use

 

Pricing_Support__c priceSupport;

 

public Pricing_Support__c getpriceSupport(){

           if(priceSupport==null)

                    priceSupport = new Pricing_Support__c();

           return priceSupport;

}

 

 

try both and see if any one of them works. Most probably the first one could be the one causing the problem.

 

This was selected as the best answer
sales4cesales4ce

Thanks Sravu. It was the second option that i missed and it worked like charm.

 

Sales4ce