jsfprimefacesprimefaces-datatable

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


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 filter fields "Code", "Data do Registro" and "Usuário" to manipulate in a backing bean.

enter image description here


Solution

  • You can get the filter value from the datatable by

    1. Obtain a reference to the datatable from the view either by binding or walking the tree. By binding, you'll 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 backing bean:

         DataTable theDataTable = new DataTable();
         //getter and setter
      
    2. From the binding

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