I'm pretty sure I'm missing something really simple here. I've done this a number of times, but even using my past examples I just can't seem to get this to work.
Scenario: I have a Page using a StandardController and Extension. This page has two Select List components. The Second SelectList (MajorCategory) has it's options set based on the value in the first SelectList (UserType).
When the User picks a value for UserType I want the MajorCategory to rerender and display values based on the selected value from UserType. I've done two methods to do this.
The first was an ActionFunction that has the value passed as a Param and renders the OutputPanel for MajorCategory.
The Second is an ActionSupport on the UserType that rerenders the Outputpanel for MajorCategory.
Neither Method seems to set the value of UserType and therefore my second picklist never gets updated with selectOptions. I added a system.debug in the SelectOptions method for MajorCategory and everytime it shows that UserType hasn't been set based on the value on the page.
<apex:page showheader="false" sidebar="false" standardStylesheets="false" standardController="Case" extensions="Case_ContactUs_Ext">
<style>
.MyClass{font-weight:bold;}
</style>
<apex:form >
<apex:actionFunction name="RefreshCategories" rerender="MajorCategory, CategoryPanel" >
<apex:param name="firstParam" assignTo="{!UserType}" value="" />
</apex:actionFunction>
<apex:outputlabel value="User Type Prototype:" style="padding-right:5px;" />
<apex:SelectList value="{!UserType}" required="true" size="1" onchange="RefreshCategories(this.value)">
<apex:selectoptions value="{!UserTypes}" />
<!-- <apex:actionsupport event="onchange" rerender="MajorCategory, CategoryPanel" /> -->
</apex:SelectList>
<br/>
<apex:outputpanel id="CategoryPanel">
ViewMe: {!ViewMe}<br/>
<apex:outputlabel value="Major Category ProtoType:" style="padding-right:5px;" />
<apex:SelectList value="{!MajorCategory}" required="true" size="1" id="MajorCategory">
<apex:selectOptions value="{!Categories}" />
</apex:SelectList>
</apex:outputpanel>
</apex:form>
ViewME is a test Boolean that is set to confirm the outputpanel is rendered properly.
Here's the controller:
public class Case_ContactUs_Ext {
private final Case c;
private final ID vOwnerID;
public string vContactFirstName{get;set;}
public string vContactLastName {get;set;}
public string vEmail {get;set;}
public string vCity {get;set;}
public string vState {get;set;}
public string vComment {get;set;}
public static boolean ErrorTest = false;
/*Constructor Method
*/
public Case_ContactUs_Ext(ApexPages.StandardController con) {
ViewMe = false; UserType ='IHaventChanged!';
this.c = (Case)con.getRecord();
list<Group> Queues = [SELECT DeveloperName,Email,Id,Name,OwnerId,RelatedId,Type
FROM Group WHERE Type = 'Queue' AND DeveloperName = 'CustomerSupportQueue'];
if(Queues != null && Queues.size()>0 && ErrorTest == false){
vOwnerID = Queues[0].id;
}else{
list<User> lUser = [SELECT Id,Name,ProfileId,Profile.Name FROM User where Profile.Name = 'System Administrator'];
vOwnerID = lUser[0].id;
}
}
/*SetDefaults on Case based on Page Params
*/
public void SetCaseDefaults(){
map<string,string> PageParams = ApexPages.currentPage().getParameters();
c.Subject = c.Reason_L1__c;
c.OwnerID = vOwnerID;
string pwid = PageParams.get('PWID');
string sponsor = PageParams.get('Sponsored');
string vDesc = 'Contact First Name: ' + vContactFirstName + '\r\n Contact Last Name: ' + vContactLastName +
'\r\n Contact Email: ' + vEmail + '\r\n PWID: ' + pwid + '\r\n Sponsored: ' + Sponsor + '\r\n Comment: ' + vComment;
C.Case_Web_Source__c = PageParams.get('Source');
C.Origin = 'Web';
c.Contact_City__c = vCity;
c.Contact_State__c = vState;
c.Description = vDesc;
}
public string UserType {get; set;}
/*Usertype Picklist Values
*/
public list<SelectOption> getUserTypes(){
list<SelectOption> options = new list<SelectOption>();
map<String, Custom_Picklist_Values__c> mValues = Custom_Picklist_values__c.getAll();
options.add(new SelectOption('',''));
integer i=0;
for(Custom_Picklist_Values__c value : mvalues.values()){
options.add(new SelectOption('Test'+i, value.Name)); i++;
}
return options;
}
public boolean ViewMe {get;set;}
/*
*/
public string MajorCategory {get;set;}
public list<SelectOption> getCategories(){
system.debug('Updating Categories with values for: ' + UserType);
ViewMe = true;
list<SelectOption> options = new list<SelectOption>();
map<string, Custom_Picklist_Contraints__c> mvalues = Custom_Picklist_Contraints__c.getAll();
for(Custom_Picklist_Contraints__c value : mvalues.values()){
if(UserType != null && value.Master_Value__c == UserType){
options.add(new SelectOption(value.Dependent_Value__c, value.Dependent_Value__c));
}
}
return options;
}
//EOF
}
Update 2/8/2013 Okay now I'm really confused. I removed all the other fields on the page. I still got the same behavior.
Then in my extension, I added this:
options.add(new SelectOption(UserType, UserType));
To the method that builds the MajorCategories selection options. When this is there, the picklist gets refreshed properly!
At first I thought it was because there was no values in the picklist at all when the page first renders. So I replaced the above option.add with just 'Test','test'. This time the picklist fails to render.
Update to the Update Okay... I'm not very weirded out. Without making a single change it suddenly started working.