PrimeFaces - DataTable Filtering

[Updated: Jun 12, 2017, Created: Jun 9, 2017]

The managed bean

public class EmployeeBean {
  private List<Employee> employeeList;
  private List<Employee> filteredEmployeeList;

  public void postConstruct() {
      employeeList = DataService.INSTANCE.getEmployeeList();

  public List<Employee> getEmployeeList() {
      return employeeList;
public class Employee {
  private long id;
  private String name;
  private String phoneNumber;
  private String address;
  private String department;

The view


<p:dataTable var="employee" value="#{employeeBean.employeeList}"

    <f:facet name="header">
            <h:outputText value="Search all:"/>
            <p:inputText id="globalFilter"
                         style="width:150px" placeholder="Search text"/>

    <p:column headerText="Id" filterBy="#{}" filterMatchMode="contains">
        <h:outputText value="#{}"/>

    <p:column headerText="Name" filterBy="#{}" filterMatchMode="contains">
        <h:outputText value="#{}"/>

    <p:column headerText="Department" filterBy="#{employee.department}"
        <f:facet name="filter">
            <p:selectOneMenu onchange="PF('employeeWidget').filter()" >
                <f:selectItem itemLabel="Select dept" itemValue="#{null}" noSelectionOption="true" />
                <f:selectItems value="#{employeeBean.deptList}" />
        <h:outputText value="#{employee.department}"/>

    <p:column headerText="Phone Number" filterBy="#{employee.phoneNumber}"
        <h:outputText value="#{employee.phoneNumber}"/>

    <p:column headerText="Address" filterBy="#{employee.address}"
        <h:outputText value="#{employee.address}"/>

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war


Example Project

Dependencies and Technologies Used :

  • primefaces 6.1 primefaces
  • jsf-api 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • jsf-impl 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • datafactory 0.8: Library to generate data for testing.
  • JDK 1.8
  • Maven 3.3.9

Primefaces DataTable Filtering Example Select All Download
  • data-table-filtering
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • webapp

See Also