You need to sign in to do that
Don't have an account?
Erik Rodgers
how to access selectoption "value" selected
Hello. I am new to the Force.com platform and I am trying to understand how to access the "value" parameter value of the SelectedOption for the <apex:selectList> or <apex:selectOptions> components when the page is submitted. I want to access this selected value from my doSave method. I have searched the forum and see where a developer can bind a variable to the "label" for the Selected Option, but not the "value". For example, if I add the following SelectedOptions:
options.add(new SelectOption('789521','Some Category'));
options.add(new SelectOption('986521','Some Other Category'));
options.add(new SelectOption('143254','Yet Another Category'));
Then in my doSave method, I need to be able to access the value of the selected option (e.g., 986521) - not the label (Some Other Category) - for processing. The label was only useful for displaying to the user, not for processing (as the value I placed in the SelectOption is actually a key in an external system with which we integrate). Since we pass this value as part of the constructor for SelectOption, I would only assume there is some way to access it when submitted server-side. I would greatly appreciate any help the community can provide. Thanks!
options.add(new SelectOption('789521','Some Category'));
options.add(new SelectOption('986521','Some Other Category'));
options.add(new SelectOption('143254','Yet Another Category'));
Then in my doSave method, I need to be able to access the value of the selected option (e.g., 986521) - not the label (Some Other Category) - for processing. The label was only useful for displaying to the user, not for processing (as the value I placed in the SelectOption is actually a key in an external system with which we integrate). Since we pass this value as part of the constructor for SelectOption, I would only assume there is some way to access it when submitted server-side. I would greatly appreciate any help the community can provide. Thanks!
All Answers
Use this
options[indexnumber].getvalue()
http://www.salesforce.com/docs/developer/pages/Content/apex_pages_selectoption.htm
How would you know the value (not the label) of the selection made from the countries selectlist from the "test" method? Again, not the label, but rather the value (i.e., CANADA, not Canada)?
You can try out this function may be this could help you out
public string accessoption(string seloption){
for(integer i=0;i<lstoption.size();i++){
if(seloption == lstoption[i].getlabel()){
return lstoption[i].getvalue();
}
}
return null;
}
I don't think salesforce has built-in functionality for that.Your Mirrored Map Idea would be the best approach for your problem as you already said.