Programming Notes

Enums in JSF

| Comments

Finally I find the way to use enum with JSF: Suppose you have enum:

1
2
3
4
5
public enum ActionTypeEnum {
  UPDATE,
  CREATE,
  COPY
}

In JSF you can write EL expressions in form:

1
2
<h:outputText value="someText"
  rendered="#{listAction.actionType == 'COPY'}"/>

The property actionType in managed bean listAction have to be of type ActionTypeEnum. It works because each enum in have method valueOf(String stringValue) and JSF attempts to convert String value to enum.

Comments