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

不问归期 提交于 2019-12-09 18:13:35

问题


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.


回答1:


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.
    



回答2:


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.



来源:https://stackoverflow.com/questions/15485452/how-to-get-the-values-entered-in-the-field-filtered-datatable-of-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!