You need to sign in to do that
Don't have an account?
KidNiki
Return label value to controller from SelectList/SelectOption...
Is it possible to return the label value of the selected item in a selectlist to the controller. Sorry, Im new at this and couldn't find anything.
I just want to know what the label of the currently selected item is instead of the value (which I need different for something else)
Thank you
If you're defining your options on the VisualForce page then you'll have to do something tricky to get it done.
If you're defining your options in the Apex Controller then you can derive the Label from the value.
Tricky VF Method:
Options "hardcoded" in Apex Controller:
Or you could go an insane 3rd route and store your options and labels in a custom object in Salesforce and do SOQL queries against the table to load the values into the VF page, then store those values in a map and check the map in the yourAction method.
Hope this helps!
-g
Im not, its populated via a soql query in the controller. Im going to try and grab the value via query and post it back to the controller. Ill post my findings here. Thank you for your feedback, I didn't think it would be easy.
Since you're working in the controller I think you'd be able to use a map to store the values for reference... something like:
You've cloned the values in the
You can have a variable in the controller to keep the label of the selected option NAME just like you are keeping one to store the selected option ID. and you can instantiate it as follows:
public List<SelectOption> options {get; set;}
public string Choice {get; set;}
public string choiceName {get{
for (SelectOption so : Options){
if (so.getValue() == choice){
return so.getLabel();
}
}
return null;
}}
public String getChoice() {
return Choice;
}
This will give the selected option NAME / LABEL in the controller in choiceName variable.