How to get the values ​​entered in the Filtered DataTable of Primefaces field?

I have a data table:

<p:dataTable id="pDataTableListaRegistros" var="registro" value="#{arquivoBean.listaRegistros}" paginator="true" rows="20" filteredValue="#{arquivoBean.filteredListaRegistros}" styleClass="tabelaCentralizada"> 

I would like to get the values ​​entered in the filter fields "Code", "Data do Registro" and "Usuário" for management in a backup bean.

enter image description here

+6
source share
2 answers

You can get the filter value from datatable on

  • Get a link to the data related to the view by snapping or walking through the tree. By linking you will have:

      <p:dataTable binding="#{arquivoBean.theDataTable}" id="pDataTableListaRegistros" var="registro" value="#{arquivoBean.listaRegistros}" paginator="true" rows="20" filteredValue="#{arquivoBean.filteredListaRegistros}" styleClass="tabelaCentralizada"/> 

    And in your bean support:

      DataTable theDataTable = new DataTable(); //getter and setter 
  • Out of binding

      Map<String, String> theFilterValues = theDataTable.getFilters(); //This returns a map of column-filterText mapping. 
+6
source

You can add a card to your bean, for example:

 private Map<String, Serializable> filterValues = new HashMap<>(); 

And bind the values ​​to the map using the filterValue p:column attribute, for example:

 <p:column headerText="Name" sortBy="#{item.name}" filterBy="#{item.name}" filterMatchMode="contains" filterValue="#{yourBean.filterValues['name']}"> <h:outputText value="#{item.name}" /> </p:column> 

The advantage of this solution is that the values ​​will be preserved when the table is updated.

+1
source

All Articles