'Primefaces dataTable, filter on localized enum values

I have a p:datatable that is populated by a list of domain objects

Each domain object has a value that is tied to an enum PrivateIndustry : P, K or N , that corresponds to a database value.

these values are then presented in the p:dataTable via localization, labels_LOCALE.properties to make them human readable, with the com.package.PrivateIndustry.P/K/N syntax.

This works okay for readability, but when i Use PF('dataTableId').filter() to filter the dataTable, I cannot filter for the localized values, only the pure enum values (ie P, K or N)

ie:

    <p:column headerText="#{labels.header}"
         filterBy="#{domainobject.privateIndustry}" filterStyle="display: none"
         sortBy="#{domainobject.privateIndustry}" >
         <h:outputText value="#{domainobject.privateIndustry}"/>
    </p:column>

I can remedy this by populating the names in the domain object as String using ResourceBundle.getString("com.package.PrivateIndustry...") but this seems rather unneccesary and convoluted.

Can I parse filterBy="" with a better value, or make PF().filter() work on the client side data?



Solution 1:[1]

With this code you can manage all from the page xhtml, without touching your java beans:

<p:importEnum type="it.example.PrintRequestFormat" var="PrintRequestFormat" allSuffix="ALL_ENUM_VALUES" />
<p:column visible="true" filterBy="#{req.format.name()}" sortBy="#{req.format}" headerText="#{msg['pressroom_list.format']}" filterMatchMode="in">
    <f:facet name="filter">
        <p:selectCheckboxMenu label="#{msg['pressroom_list.format']}" onchange="PF('requestsTable').filter()" panelStyle="width:125px" scrollHeight="150">
            <f:selectItems value="#{PrintRequestFormat.ALL_ENUM_VALUES}" var="format" itemValue="#{req.format.name()}" itemLabel="#{msg['printrequest.format.'.concat(format)]}"/>
        </p:selectCheckboxMenu>
    </f:facet>
    <h:outputText value="#{msg['printrequest.format.'.concat(req.format)]}" />
</p:column>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 madx