You need to sign in to do that
Don't have an account?
adrissel
Can't send selectList value to controller via Javascript?
Hey all, I need to pass the set value of one of my selectList options back to a specific method in my controller. It isn't working and I can't find out why. Can someone glance at the code below and tell me what I'm missing here?
Controller
VF Page
Thanks ahead of time!
Controller
public class LogACaseController{ public Boolean aso {get;set;} public Boolean cd {get;set;} public Boolean ss {get;set;} private Id userId {get;set;} public String baseUrl {get;set;} public String selection {get;set;} public List<String> products = new List<String>(); /* * Get ContactId of logged-in User */ public PageReference getUserInfo(){ userId = UserInfo.getUserId(); getPermSets(userId); getBaseUrl(); return null; } /* * Get permission sets of logged-in User */ public void getPermSets(Id userId){ Id asoPsId = [SELECT Id FROM PermissionSet WHERE Name = 'ASO_Community' LIMIT 1].Id; Id ssPsId = [SELECT Id FROM PermissionSet WHERE Name = 'SS_Community' LIMIT 1].Id; Id cdPsId = [SELECT Id FROM PermissionSet WHERE Name = 'CD_Community' LIMIT 1].Id; List<PermissionSetAssignment> asoAssigneeIds = new List<PermissionSetAssignment>([SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSetId =: asoPsId]); List<PermissionSetAssignment> ssAssigneeIds = new List<PermissionSetAssignment>([SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSetId =: ssPsId]); List<PermissionSetAssignment> cdAssigneeIds = new List<PermissionSetAssignment>([SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSetId =: cdPsId]); for(PermissionSetAssignment asoId : asoAssigneeIds){ if(asoId.AssigneeId == userId){ aso = true; } } for(PermissionSetAssignment ssId : ssAssigneeIds){ if(ssId.AssigneeId == userId){ ss = true; } } for(PermissionSetAssignment cdId : cdAssigneeIds){ if(cdId.AssigneeId == userId){ cd = true; } } } /* * Get product options */ public List<SelectOption> getOptions(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('none','--None--')); options.add(new SelectOption('aso','Advanced Sourcing Optimizer')); options.add(new SelectOption('cd','Contract Director')); options.add(new SelectOption('ss','eProcurement/SelectSite')); return options; } public List<String> getProducts() { return products; } public void setProducts(List<String> products) { this.products = products; } /* * Get pagereference based on user product selection */ public PageReference getCasePage(){ PageReference pr; RecordType asoRt = [SELECT Id FROM RecordType WHERE DeveloperName = 'ASO' LIMIT 1]; RecordType cdRt = [SELECT Id FROM RecordType WHERE DeveloperName = 'Contract_Director' LIMIT 1]; RecordType ssRt = [SELECT Id FROM RecordType WHERE DeveloperName = 'SelectSite_Support' LIMIT 1]; if(aso == true){ pr = new PageReference(baseUrl+'/support/500/e?retURL=%2Fsupport%2F500%2Fo&RecordType='+asoRt.Id+'&ent=Case'); } else if(cd == true){ pr = new PageReference(baseUrl+'/support/500/e?retURL=%2Fsupport%2F500%2Fo&RecordType='+cdRt.Id+'&ent=Case'); } else if(ss == true){ pr = new PageReference(baseUrl+'/support/500/e?retURL=%2Fsupport%2F500%2Fo&RecordType='+ssRt.Id+'&ent=Case'); } return pr; } /* * Get baseUrl */ public String getBaseUrl(){ baseUrl = Url.getSalesforceBaseUrl().toExternalForm(); return baseUrl; } }
VF Page
<apex:page controller="LogACaseController" tabStyle="Log_A_Case__tab" action="{!getUserInfo}"> <head> <script> function getCasePage(){ var selection = document.getElementById("{!$component.form.product}").value; alert(selection); getCasePageFunction(selection); } </script> </head> <body> <apex:form id="form"> <apex:actionFunction action="{!getCasePage}" id="getCasePage" name="getCasePageFunction"> <apex:param assignTo="{!selection}" id="selection" name="selection" value=""/> </apex:actionFunction> <br/><span style="font-size: 14px;font-weight: bold;">Select a product:</span> <apex:selectList id="product" value="{!products}" multiselect="false" size="1" onchange="return getCasePage();"> <apex:selectOptions value="{!options}"></apex:selectOptions> </apex:selectList> </apex:form> </body> </apex:page>
Thanks ahead of time!
use this
<apex:selectList id="product" value="{!products}" multiselect="false" size="1" onchange="getCasePageFunction('{!products}');return false;">
I don't think you need a script for that for passing value to controller.
Hope this helps.
Just to be clear here is what I'm wanting to happen...I want to select an option from the list and have the page redirect to the corresponding PageReference. To test whether it is even getting to the getCasePage() method at all I have a system.debug statement in there. When making a selection from the list the screen merely refreshes but there is no record of my debug statement in the logs and no indication that it is even going into the method at all.
What else am I missing?
change this line
public List<String> products = new List<String>();
to
public string products{get;set;}
and remove it's getter/setter methods from class
and now try to see your debug statement
this wil work.
Please use return false; statement at the end of the getCasePage(selection) function.