I am trying to understand the usage of SelectList tag.
Below is the code that I expect to give me the selected Value from all the list of values in the drop down. Populating the dropdown dynamically with the list of recordTypes. But am unable to get the value selected by the user.
I have also tried adding the actionsupport
tag to see if on change event it will call the Apex Method and execute the debug statement under fetchVAL()
, but I don't see it to be executing as well. Please advise how I can fetch the value of selected Record Type and do we need the action support tag here?
<apex:page controller="chooseColor">
<apex:form>
<apex:selectList id="chooseRecType" value="{!RecType}" size="1">
<apex:actionSupport event="onchange" rerender="list" action="{!fetchVAL}"/>
<apex:selectOptions value="{!RecTypeVals}">
</apex:selectOptions>
</apex:selectList>
<p id= "list">display : {!a}</p>
</apex:form>
public class chooseColor {
public string a {
get {
return RecType;
}
set;
}
public string RecType {
get;
set {
a = RecType;
system.debug('a===' + a);
}
}
public List < SelectOption > RecTypeVals {
get {
List < SelectOption > SOp = new List < SelectOption > ();
for (RecordType rt: [SELECT Id, Name FROM RecordType where SobjectType = 'Opportunity']) {
system.debug('rt : ' + rt);
SOp.add(new SelectOption(rt.name, rt.name));
}
system.debug('options : ' + SOp);
return SOp;
}
}
public void fetchVAL() {
system.debug('RecType : ' + RecType); // to check if the selected Value from optionlist is captured.
}
}