Search code examples
primefacesfilterdatatableomnifaceshttp-request-parameters

PrimeFaces Datatable filtering removed when sorting with o:form includeRequestParams="true"


this is an issue following this one: PrimeFaces datatable.filter() and url parameter

is use PrimeFaces-5.1 and omnifaces-2.1 to render a datatable with pagination, filtering and sorting while using request parameters. my datatable is constructed like this:

<o:form includeRequestParams="true">
    <p:dataTable id="hostStateHistoryTable" value="#{HostHistoryBean.hostStateHistoryList}" var="status" widgetVar="statusTable"
    filteredValue="#{HostHistoryBean.filteredHostStateHistoryList}" 
    rowStyleClass="#{status.state eq 0 ? 'up' : null} #{status.state   eq 1 ? 'down' : null} #{status.state eq 2 ? 'unreachable' : null}"
    rows="50" paginator="true" paginatorTemplate="{PageLinks} {RowsPerPageDropdown}" rowsPerPageTemplate="10,50,100">
        <p:column sortBy="#{status.stateTime}">
            <f:facet name="header">Start Time</f:facet>
            <h:outputText id="Start" value="#{status.stateTime}"     />
        </p:column> 
        ... all columns
    </p:dataTable>
</o:form>

But Sorting is removing the PrimeFaces Datatable Filtering. I can sort alone and filter alone without problem, but when i sort the datable after filtering it remove the filter. again Clicking on the same filter won't do anything but filtering on another value will display the expected result. It seems that the o:form will resend the request, including attribute, instead of using the datatable filteredValue.

Edit: I uploaded an eclipse based MCVE project here: http://www.dacave.fr/stackoverflow/test.faces.rar


Solution

  • Ok so i found out that filteredValue was reseted on each ajax call because of the @RequestScoped. I think i was kind of mixing up things. So i switched all @ManagedBeans to @Named then i created a new @SessionScoped Bean with most of the attributes and i @inject a @RequestScoped bean with the request based attributes into it.

    Now everything works as expected