6

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sant
  • 386
  • 2
  • 6
  • 17
  • I know to get the value entered in a . This is possible through the get and set methods of backingBean. However I do not know to get the value entered in a field Filtered column: – Sant Mar 18 '13 at 19:58
  • You should not do that in a getter/setter method. They should be kept untouched and not do anything else than just returning and setting a property. You should just access the `listaRegistros` in the action method. JSF has already set the values in there. – BalusC Mar 18 '13 at 20:00
  • i don´t know how to get the values typed by the user in the column. – Sant Mar 18 '13 at 20:16

2 Answers2

8

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.
    
kolossus
  • 20,559
  • 3
  • 52
  • 104
1

You can add a map to your bean, like:

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

And bind the values to the map using the filterValue attribute of p:column, 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>

Advantage of this solution is that the values will be kept when you update your table.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102