Ok,here is the final way:- Register the standard enum converter in faces-config.xml (optional):
<converter> <converter-for-class>java.lang.Enum</converter-for-class> <converter-class>javax.faces.convert.EnumConverter</converter-class> </converter>
Add a function for example to a managed bean which converts the Enum values to an array of SelectItems:
@ManagedBean public class GenderBean { public SelectItem[] getGenderValues() { SelectItem[] items = new SelectItem[Gender.values().length]; int i = 0; for(Gender g: Gender.values()) { items[i++] = new SelectItem(g, g.getLabel()); } return items; } }
Then bind this function to the selectOneMenu in JSF:
<h:selectOneMenu id="gender" value="#{person.gender}"> <!-- use property name not method name --> <f:selectItems value="#{genderBean.genderValues}" /> </h:selectOneMenu>
That's it! Not the first explanation for this problem on the net. But i think it's the easiest & shortest one ;)