我正在尝试对我的数据表使用过滤。每当表第一次加载时,它看起来像这样:
如果我在用户名过滤器中输入文本,表格如下所示:
我希望它只显示 dangreen87,因为 mike.smith 不包含“d”。然而,它不显示任何用户名。我不确定这种行为是什么?
我有一个像这样的数据表:
<h:body>
<ui:composition>
<h:panelGroup layout="block" styleClass="messagesPanel" rendered="#{socialAdvertiserManagedBean.displaySearch}" >
<p:dataTable
resizableColumns="true"
var="account"
value="#{searchManagedBean.accountsToDisplay}"
scrollable="true"
paginator="true"
rows="10"
rowKey="#{account.id_value}"
emptyMessage="No accounts found for the given criteria"
widgetVar="searchTable"
filteredValue="#{searchManagedBean.filteredAccounts}">
<f:facet name="header">
#{searchManagedBean.isCompany ? 'Company' : 'Social Advertisers'}
</f:facet>
<p:column headerText="Image">
<p:graphicImage value="/dbimages/#{accountManagedBean.getImageId(account)}" width="25" height="25"/>
</p:column>
<c:if test="#{searchManagedBean.isCompany}" >
<p:column headerText="Company Name">
<h:outputLabel value="#{accountManagedBean.getCompany(account).name}" />
</p:column>
</c:if>
<c:if test="#{not searchManagedBean.isCompany}" >
<p:column id="userNameColumn" filterBy="#{account.userName}" filterMatchMode="contains">
<f:facet name="header">
<h:outputLabel value="User Name"/>
</f:facet>
<h:outputLabel value="#{account.userName}" />
</p:column>
</c:if>
</p:dataTable>
我的支持 bean 看起来像这样:
@ManagedBean
@ViewScoped
public class SearchManagedBean implements Serializable
{
private boolean isCompany;
private Account selectedAccount;
@EJB
private AccountDao accountDao;
@EJB
private SocialAdvertiserDao socialAdvertiserDao;
@EJB
private CompanyDao companyDao;
private List<Account> filteredAccounts;
@PostConstruct
public void init()
{
isCompany = true;
}
public List<Account> getAccountsToDisplay()
{
List temp;
if(isCompany)
{
temp = companyDao.findAll();
}
else
{
temp = socialAdvertiserDao.findAll();
}
return temp;
}
public List<Account> getFilteredAccounts() {
return filteredAccounts;
}
public void setFilteredAccounts(List<Account> filteredAccounts) {
this.filteredAccounts = filteredAccounts;
}
public boolean getIsCompany() {
return isCompany;
}
public void setIsCompany(boolean isCompany) {
this.isCompany = isCompany;
}
....