我为包含字符串值的列制作了过滤器。有用。但同样的方法不适用于日期。当我选择某个日期时,它不会过滤任何内容,但是当我在过滤器中选择空值时,它会显示所有日期。所以它有效,但是日期有问题:(
有字符串值的代码:
<rich:column filterValue="#{clientBean.confirmFilter}"
filterExpression="#{fn:containsIgnoreCase(client.conferm,
clientBean.confirmFilter)}">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Filter " />
<h:selectOneMenu value="#{clientBean.confirmFilter}">
<f:selectItems value="#{clientBean.listConfirmFilter}" />
<a4j:ajax render="table" execute="@this" event="change" />
</h:selectOneMenu>
</h:panelGroup>
</f:facet>
<h:outputText value="#{clientBean.getConfirmValue(client.conferm)}" />
</rich:column>
日期代码:
<rich:column filterValue="#{clientBean.dataOpenFilter}"
filterExpression="#{fn:containsIgnoreCase(client.dataOpen,
clientBean.dataOpenFilter)}">
<f:facet name="header">
<h:panelGroup>
<a4j:outputPanel layout="block">
<rich:calendar value="#{clientBean.dataOpenFilter}" locale="ru/RU"
popup="true" datePattern="dd/MM/yyyy"
showApplyButton="false" cellWidth="24px" cellHeight="22px"
disabled="false" >
<a4j:ajax render="table" execute="@this" event="change" />
</rich:calendar>
</a4j:outputPanel>
</h:panelGroup>
</f:facet>
<h:outputText value="#{client.dataOpen}" locale="ru/RU" >
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</rich:column>
还有我的托管豆:
private String confirmFilter;
private List<SelectItem> listConfirmFilter;
private Date dataOpenFilter;
...
public String getConfirmFilter() {
return confirmFilter;
}
public void setConfirmFilter(String confirmFilter) {
this.confirmFilter = confirmFilter;
}
public List<SelectItem> getListConfirmFilter() {
listConfirmFilter = new ArrayList<SelectItem>();
listConfirmFilter.add(new SelectItem("",""));
listConfirmFilter.add(new SelectItem("N","Not confirmed"));
listConfirmFilter.add(new SelectItem("Y","Confirmed"));
return listConfirmFilter;
}
public Date getDataOpenFilter() {
return dataOpenFilter;
}
public void setDataOpenFilter(Date dataOpenFilter) {
this.dataOpenFilter = dataOpenFilter;
}
我解决了这个问题:
public Filter<Client> getDateOpenFilterImpl() {
return new Filter<Client>() {
public boolean accept(Client client) {
Date dataOpenFilter = getDataOpenFilter();
if (dataOpenFilter == null ||
dataOpenFilter.compareTo((Date)client.getDataOpen())==0) {
return true;
}
return false;
}
};
}
<rich:column filter="#{clientBean.dateOpenFilterImpl}" ...