@ManagedBean @ViewScoped public class EmployeeBean { private List<Employee> employeeList; private List<Employee> filteredEmployeeList; @PostConstruct 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; //getters/setters ............. }
<p:dataTable var="employee" value="#{employeeBean.employeeList}" filteredValue="#{employeeBean.filteredEmployeeList}" widgetVar="employeeWidget"> <f:facet name="header"> <p:outputPanel> <h:outputText value="Search all:"/> <p:inputText id="globalFilter" onkeyup="PF('employeeWidget').filter()" style="width:150px" placeholder="Search text"/> </p:outputPanel> </f:facet> <p:column headerText="Id" filterBy="#{employee.id}" filterMatchMode="contains"> <h:outputText value="#{employee.id}"/> </p:column> <p:column headerText="Name" filterBy="#{employee.name}" filterMatchMode="contains"> <h:outputText value="#{employee.name}"/> </p:column> <p:column headerText="Department" filterBy="#{employee.department}" filterMatchMode="exact"> <f:facet name="filter"> <p:selectOneMenu onchange="PF('employeeWidget').filter()" > <f:selectItem itemLabel="Select dept" itemValue="#{null}" noSelectionOption="true" /> <f:selectItems value="#{employeeBean.deptList}" /> </p:selectOneMenu> </f:facet> <h:outputText value="#{employee.department}"/> </p:column> <p:column headerText="Phone Number" filterBy="#{employee.phoneNumber}" filterMatchMode="contains"> <h:outputText value="#{employee.phoneNumber}"/> </p:column> <p:column headerText="Address" filterBy="#{employee.address}" filterMatchMode="contains"> <h:outputText value="#{employee.address}"/> </p:column> </p:dataTable>
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Dependencies and Technologies Used: