I'm trying to use an enum with a h:selectOneMenu box in a JSF2 project.
What I've got so far:
Enum:
public enum MyType {
TEST,
ME;
}
Backing bean:
@ManagedBean
public class MyBean {
private MyType type;
public MyType[] getTypes {
return MyType.values;
}
public void setType(MyType type) {
this.type = type;
}
public MyType getType() {
return this.type;
}
}
xhtml page:
<h:selectOneMenu id="mySelection"
value="#{myBean.type}">
<f:selectItems value="#{myBean.types}" />
</h:selectOneMenu>
My problem is that the values are correctly displayed but they are not saved (I'm actually using it in a seam3 hibernate project). When I tried it with a custom validator, I saw that the setType method is called twice, the second time with null -> resulting that nothing is saved. Am I missing anything?
So far I've checked the following topics:
* jsf-2-0-use-enum-values-for-selectonemenu
* jsf-2-0-use-enum-in-selectmany-menu
* jsf-best-way-to-enum-internationalization-i18n
Thanks a lot for your help,
Stephan