You need to sign in to do that
Don't have an account?
Apex class and VF page with actionsupport
I have the following Apex class and VF page. Based on the selection of the tite, the corresponding role should display. I am using the actionSupport to pass the selected value onchange event, and assign the value to selectedTitle. But the selectedTitle is null everytime. Any ideas?
Apex class:
public class selectListController
{
public String title { get; set; }
public String role { get; set; }
public String selectedTitle { get; set; }
public List<selectOption> titleList { get; set; }
public List<selectOption> roleList { get; set; }
public selectListController()
{
titleList = new List<selectOption>();
titleList.add(new SelectOption('', '--None--'));
for (TitleRoleAssociation__c title : [Select Title_Definition__r.Name from TitleRoleAssociation__c]) {
titleList.add(new selectOption(title.Title_Definition__r.Id, title.Title_Definition__r.Name));
}
}
public PageReference getRoles(){
roleList = new List<selectOption>();
roleList.add(new SelectOption('', '--None--'));
System.debug('Selected title: ' + selectedTitle);
for (TitleRoleAssociation__c role : [Select Role_Definition__r.Name from TitleRoleAssociation__c where Title_Definition__r.Name = :selectedTitle]) {
roleList.add(new selectOption(role.Role_Definition__r.Id, role.Role_Definition__r.Name));
}
return null;
}
}
VF page:
<apex:page controller="selectListController">
<apex:form>
<apex:selectList value="{!title}" multiselect="false" size="1">
<apex:selectOptions value="{!titleList}" />
<apex:actionSupport event="onchange" action="{!getRoles}" reRender="role" status="status">
<apex:param name="selectedTitle" value="{!title}" assignTo="{!selectedTitle}"/>
</apex:actionSupport>
</apex:selectList>
<apex:outputPanel id="role">
<apex:selectList value="{!role}" multiselect="false" size="1">
<apex:selectOptions value="{!roleList}" />
</apex:selectList>
</apex:outputPanel>
</apex:form>
</apex:page>
Apex class:
public class selectListController
{
public String title { get; set; }
public String role { get; set; }
public String selectedTitle { get; set; }
public List<selectOption> titleList { get; set; }
public List<selectOption> roleList { get; set; }
public selectListController()
{
titleList = new List<selectOption>();
titleList.add(new SelectOption('', '--None--'));
for (TitleRoleAssociation__c title : [Select Title_Definition__r.Name from TitleRoleAssociation__c]) {
titleList.add(new selectOption(title.Title_Definition__r.Id, title.Title_Definition__r.Name));
}
}
public PageReference getRoles(){
roleList = new List<selectOption>();
roleList.add(new SelectOption('', '--None--'));
System.debug('Selected title: ' + selectedTitle);
for (TitleRoleAssociation__c role : [Select Role_Definition__r.Name from TitleRoleAssociation__c where Title_Definition__r.Name = :selectedTitle]) {
roleList.add(new selectOption(role.Role_Definition__r.Id, role.Role_Definition__r.Name));
}
return null;
}
}
VF page:
<apex:page controller="selectListController">
<apex:form>
<apex:selectList value="{!title}" multiselect="false" size="1">
<apex:selectOptions value="{!titleList}" />
<apex:actionSupport event="onchange" action="{!getRoles}" reRender="role" status="status">
<apex:param name="selectedTitle" value="{!title}" assignTo="{!selectedTitle}"/>
</apex:actionSupport>
</apex:selectList>
<apex:outputPanel id="role">
<apex:selectList value="{!role}" multiselect="false" size="1">
<apex:selectOptions value="{!roleList}" />
</apex:selectList>
</apex:outputPanel>
</apex:form>
</apex:page>
I have removed errors in your code and it is working fine in my org.
Please update your code by below code.
Controller.
VF Page: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
All Answers
I have removed errors in your code and it is working fine in my org.
Please update your code by below code.
Controller.
VF Page: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Perfect. Thank you!
Bryan