In order for your <p:selectOneMenu>
item to show the description in the options you must specify which property should be shown by the itemLabel
attribute.
Standard JSF does not have the necessary support for what you need with ENUMS. So we have to turn to other support libraries. In this case, the PrimeFaces Extensions library has enhanced ENUMS support for JSF.
Using PrimeFaces Extensions your code looks like this:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:pe="http://primefaces.org/ui/extensions"> <!-- Importação da biblioteca no XHTML -->
<pe:importEnum type="leiEditMB.enumTipoLei" var="enum" allSuffix="ALL_ENUM_VALUES" />
<p:selectOneMenu value="#{leiEditMB.bean.enumTipoLei}">
<f:selectItens value="#{enum.ALL_ENUM_VALUES}" var="e"
itemLabel="#{e.descricao}" itemValue="#{e}" />
</p:selectOneMenu>
ENUM values can be accessed through the class name (default configuration) or through a custom name (attribute var
, in code above var="enum"
).
It is also possible to get all the ENUMS of the class with the suffix "ALL_VALUES" (default) or a custom prefix through the allSuffix
attribute (in the above code I used allSuffix="ALL_ENUM_VALUES"
).
More information about the <pe:importEnum>
component: link