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
Cloud on FireCloud on Fire 

can't access picklist selected value in ajax rerender

I have 2 picklists, the second dependent on the first, which work. Then an outputpanel based on the 2nd picklist. When I call the actionSupport tag to rerender the outputpanel based on the value of the 2nd picklist, I keep getting a null value for the picklist, thus ultimately causing a crash.

 

Visualforce:

 

<apex:page controller="TranscriptController" tabStyle="Account" title="Select a Transcript for {!student.name}">
      <apex:sectionHeader title="Select a Transcript Page for {!student.name}"/>
      <p>&lt; <a href="/{!student.id}">Back to {!student.name}'s Record Page</a><br/></p>
  <apex:pageBlock mode="detail">
      <apex:pageBlockButtons ><apex:form ><apex:commandButton action="{!studentRecordPage}" value="Return to Student Record"/></apex:form></apex:pageBlockButtons>
      <apex:pageBlockSection columns="1" >
      	<apex:form id="transcriptForm">
      	  <p>Program:&nbsp;<apex:selectList id="programList" size="1" value="{!selectedProgram}">
      	  	  <apex:selectOptions value="{!programList}" />
	       	  <apex:actionSupport event="onchange" rerender="degreeList"/>
      	  </apex:selectList>
      	  </p>
      	  <p>Degree:&nbsp;<apex:selectList id="degreeList" size="1" value="{!selectedDegree}"> <apex:selectOptions value="{!degreeList}" /> <apex:actionSupport event="onchange" rerender="pageList" /> </apex:selectList></p>
      	  <apex:outputPanel id="pageList" rendered="{!NOT(ISNULL(selectedDegree))}"> <apex:repeat value="{!pageList}" var="page"> <p><a href="{!page.value}" target="_blank">{!page.label}</a></p> </apex:repeat> </apex:outputPanel>
        </apex:form>
      </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

 When a value is selected from degreeList, I want pageList to be updated with a series of links for the selected degree.

 

Controller (snippets):

public with sharing class TranscriptController {


    public List<SelectOption> pageList;
    public List<SelectOption> programList;
    public List<SelectOption> degreeList;
    public String selectedProgram {get;set;}
    public Id selectedDegree {get;set;}



    Degree__c getDegree() {
    	if(degree == null) {
			String did = util.getUrlParam('degree');
			System.debug('VAR did == '+did);
			if(did == null || did.equals('null')) {
			System.debug('VAR did == NULL!!!');
				did = selectedDegree;
			System.debug('VAR selectedDegree == '+selectedDegree);
			System.debug('VAR did = '+did);
			} 
			did = String.escapeSingleQuotes(did);
			degree = [select id, name, credits_needed__c, course_codes__c from Degree__c where id = :did limit 1];
    	}
    	return degree;
    }
    

    public List<SelectOption> getPageList() {
			System.debug('getPagelist: VAR selectedDegree == '+selectedDegree);
        List<SelectOption> options = new List<SelectOption>();
        Integer numTerms = getCourseMap(getDegree()).keyset().size();
        Integer termsPerPage = TPC * 2;
        Integer i = 0;
        for(;numTerms>0;numTerms-=termsPerPage) {
            System.debug('NUMBER OF TERMS: '+numTerms);
            options.add(new SelectOption('/apex/transcript?studentid='+
                util.getUrlParam('studentid')+'&sp='+i*termsPerPage+
                '&program='+selectedProgram+'&degree='+selectedDegree,
                'Transcript Page #'+(++i)));
        
        }
        return options;
    }
    

    public List<SelectOption> getDegreeList() {
 			System.debug('getDegreelist VAR selectedProgram == '+selectedProgram);
        List<SelectOption> options = new List<SelectOption>();
			options.add(new SelectOption('','-Please Select-'));    	
        if(selectedProgram == null)
        	selectedProgram = PROGRAM_A;
        List<Degree__c> degrees = [select id, name from Degree__c where Program__c=:selectedProgram];
        for(Degree__c d : degrees)
			options.add(new SelectOption(d.id,d.name));    	
		return options;    	
    }
    

 When the getter for pageList is called, it calles a method called getDegree which first tried to get it from a URL param and if it doesn't exist there, it should get it from the property SelectedDegree which is bound to the Degree Picklist.

 

However selectedDegree is alway null, thus causing the String.escapeSingleQuotes method to throw an Invalid Argument Exception.

 

How can I get the value of the picklist passed back to the controller in order to rerender pageList?

 

Thanks.

TejTej
bob_buzzardbob_buzzard

Often when it appears that the value isn't being set back into the controller, its actually another error that is stopping the submit of the form or the processing.  I'd suggest you add an apex:pageMessages component to your page and add the id of that component to all your rerenders - that way you'll be able to see if an error is occurring.