You mean the option label? If you're using SelectItem, then you can specify the String label as 2nd parameter.
SelectItem selectItem = new SelectItem(someObject, "The label to be shown in menu");
Otherwise by default the value of someObject.toString() will be used as label.
You also can override it by
public class SomeObject {
public String toString() {
return this.name; // Change the String representation of your object here.
}
}
and then stay using
SelectItem selectItem = new SelectItem(someObject);
Also see the [url=http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/model/SelectItem.html]SelectItem API[/url].
I usually just use a hashmap to store the value and label, if I want to retrieve the label again later.
HashMap bleh = new HashMap();
bleh.put(dropDownValue, "Drop Down Label"); //Item value (any object), Item Label (String)
Iterator it = bleh.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
SelectItem selectItem = new SelectItem(key, bleh.get(key));
}
//And then later, when you want to retrieve the label
bleh.get(itemValue); //The item value of the label you want
The value is easy to get because the selected item(s) from the list will be set to the value(s) the user selected. You should have a getter in your bean for that.
CowKing
Message was edited by:
IamCowKing