【发布时间】:2018-01-27 21:31:50
【问题描述】:
这是我的 xhtml 页面
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{templateSelection.selectedTemplate}">
<ui:define name="docTitle">User Management</ui:define>
<ui:define name="body">
<h:form>
<p:dataTable id="usrDT" var="usr" value="#{userListController.userBeans}"
rows="15" paginator="true"
rowIndexVar="row"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginatorPosition="bottom"
filteredValue="#{userListController.filteredUserBeans}"
>
<f:facet name="header">
User Management
<p:outputPanel>
<h:outputText value="Search all fields:"/>
<p:inputText id="globalFilter" onkeyup="PF('usrDT').filter()" style="width:150px"
placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:column filterBy="#{row + 1}" headerText="Sl No" width="4%">
<h:outputText value="#{row + 1}"/>
</p:column>
<p:column filterBy="#{usr.userName}" headerText="User Name" width="30%">
<h:outputText value="#{usr.userName}"/>
</p:column>
<p:column filterBy="#{usr.userLoginId}" headerText="User ID" width="8%">
<h:outputText value="#{usr.userLoginId}"/>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
这是我的豆
@ManagedBean
@ViewScoped
public class UserListController {
@ManagedProperty("#{userServiceLayer}")
private UserServiceLayer userServiceLayer;
private List<UserBean> userBeans;
private List<UserBean> filteredUserBeans;
@PostConstruct
public void init() {
userBeans = userServiceLayer.getAllUserListForSearch(state, sessionScId);
}
public List<UserBean> getFilteredUserBeans() {
return filteredUserBeans;
}
public void setFilteredUserBeans(List<UserBean> filteredUserBeans)
{
this.filteredUserBeans = filteredUserBeans;
}
public List<UserBean> getUserBeans() {
return userBeans;
}
public void setUserBeans(List<UserBean> userBeans) {
this.userBeans = userBeans;
}
}
我正在创建一个显示用户列表的数据表,我想在这里添加搜索功能。我已经按照这里的描述添加了这个 https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml 。 在单列中搜索工作正常......但全局搜索不起作用......
【问题讨论】:
-
您的数据表指定
id="usrDT",其中示例使用widgetVar属性,而不是id。 -
<p:column filterBy="#{car.brand}" headerText="Brand" footerText="exact" filterMatchMode="exact">,你需要为你的filterMatchMode设置值
标签: java jsf primefaces filter datatable