Is there any way to retrieve the label of the selected
option from a select? Select.getValue() returns the value
of the selected option, but Select.getLabel() returns the
label of the select, not the label of the option.
I think this is correct so: each Click Control has a "label": the displayed
tag near a field.
A select consists of "option" tags, and there can be more than one
selected option.
So you basically want the label of an option, and in this case of the
selected one:
-------------
String foundValue = mySelect.getValue();
//if you don't have the reference to the model where you created it.
List allOptions = mySelect.getOptionList();
for (Option option : allOptions){
if(option.getValue().equals(foundValue)
System.out.println("Found Label:" + option.getLabel());
}
-------------
If you need all the time the "label" for options than is simpler to use
------
new Option("label");
------
this way the "value" and the "label" will be the same, so
Select#getValue() will return what you need.
Demetrios.