You need to sign in to do that
Don't have an account?

Help with Controller extension
I am creating a visualforce page, and I would like an action to occur "onchange" of a picklist.
Here is what I have for the visualforce page for the section I am trying to rerender:
<apex:pageBlockSectionItem > <apex:outputLabel value="Stage" /> <apex:selectList value="{!SelectedStage}" size="1"> <apex:selectOptions value="{!StageOptions}" /> <apex:actionSupport reRender="oppForm" event="onchange" status="showCloseoutSection" /> </apex:selectList> </apex:pageBlockSectionItem> <apex:actionStatus startText="(rendering closeout information...)" id="showCloseoutSection"/> </apex:pageBlockSection> <apex:actionRegion > <apex:pageBlockSection title="Closeout Information" rendered="{!Opportunity.StageName == 'Contract Signed'}" id="closeoutBlock" columns="1"> <apex:inputField value="{!Opportunity.Win_Lost_Reason__c}"/> <apex:inputField value="{!Opportunity.Competitor_Lost_To_Or_Replaced__c}"/> <apex:inputField value="{!Opportunity.Price_CT_Prelim__c}"/> </apex:pageBlockSection> </apex:actionRegion>
Here is what I have so far for my controller:
public class OpportunityClosedLost { public Opportunity opp; public apexpages.standardController controller {get; set;} //Used to determine if the action is an insert or update. public Boolean bUpdate{get; set;} public opportunityClosedLost(ApexPages.StandardController stdController) { // constructor controller = stdController; this.opp= (Opportunity)stdController.getRecord(); Opportunity opps = (Opportunity)stdController.getRecord(); opps = [SELECT RecordTypeId, StageName FROM Opportunity WHERE id=:system.currentpageReference().getparameters().get('id')]; //VRC opportunity if(opps.RecordTypeId =='012700000009RIb'){ isVrc = true; } //vRad Alliance Opportunity if(opps.RecordTypeId =='012R00000000M08'){ isAlliance = true; } //EC Opportinity if(opps.RecordTypeId =='012700000005KwS'){ isEc = true; } } public List<SelectOption> getStageOptions(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('null','-- Select One --')); Schema.DescribeFieldResult oppStage = Schema.sObjectType.Opportunity.fields.StageName; for (Schema.PickListEntry oppPickVal : oppStage.getPicklistValues()){ // create a selectoption for each pickval options.add(new SelectOption(oppPickVal.getValue(),oppPickVal.getLabel())); } return options; } public Boolean isVrc{ get{ if(isVrc == null){ isVrc = false; } return isVrc; } set; } public Boolean isAlliance{ get{ if(isAlliance == null){ isAlliance = false; } return isAlliance; } set; } public Boolean isEc{ get{ if(isEc == null){ isEc = false; } return isEc; } set; } public String SelectedStage{ get {return SelectedStage;} set; } }
Right now it does not render the pageblocksection that has the <actionRegion> tags around it. Any suggestions as to what I am doing wrong or as to why it is not rendering? The actionstatus does appear even though nothing is rendered. I also noticed that when i select an option from the picklist that is suppose control the rendering of the pageblocksection The option does not get saved when save is clicked.
Thanks!
Just had a closer look.
The property used to store the selected value from the picklist isn't the same as that which controls the rendering of the section.
When the user selects a value it will be stored into SelectedStage. This appears to be a simple string property on your controller.
The section is rendered based on Opportunity.StageName == 'Contract Signed'.
Unless you update Opportunity.StageName from the SelectedStage value, the section will remain unrendered.
All Answers
A couple of things:
You haven't defined an action method for your action support component.
You are re-rendering oppForm when the picklist changes - I assume this is wrapping the page snippet you have shown us?
Try wrapping the pageBlockSection in an outputPanel and re-rendering that.
Just had a closer look.
The property used to store the selected value from the picklist isn't the same as that which controls the rendering of the section.
When the user selects a value it will be stored into SelectedStage. This appears to be a simple string property on your controller.
The section is rendered based on Opportunity.StageName == 'Contract Signed'.
Unless you update Opportunity.StageName from the SelectedStage value, the section will remain unrendered.
Thank you for your help, I think I have been staring at that extension and page way too long. So I have eliminated the SelectedStage property and now the render works. I am still rendering the form and it works this way. So now the Dilemma is that the stages all appear in a list instead of a dropdown menu(picklist).
Once this section of the vf page was changed to this: <apex:selectList value="{!Opportunity.StageName}">
<apex:pageBlockSectionItem > <apex:outputLabel value="Stage" /> <apex:selectList value="{!Opportunity.StageName}" > <apex:selectOptions value="{!StageOptions}" /> <apex:actionSupport reRender="oppForm" event="onchange" status="showCloseoutSection" /> </apex:selectList> </apex:pageBlockSectionItem> <apex:actionStatus startText="(rendering closeout information...)" id="showCloseoutSection"/>
I guess I am just having issues with the concept of the selectList and selectOptions. Any suggestions as of a good way to explain the use of selectList and selectOptions better than the force.com Developer Guide?