Richfaces过滤日期列



我为包含字符串值的列制作了过滤器。它的工作原理。但同样的方法不起作用的日期。当我选择一些日期它不过滤任何东西,但当我在过滤器中选择空值它显示所有日期。所以它可以工作,但是日期有问题:(

有字符串值的代码:

    <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>

和我的managedBean:

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}" ...

似乎您正在尝试使用String过滤的方法来过滤Date:

fn:containsIgnoreCase(client.dataOpen, clientBean.dataOpenFilter)

相关内容

  • 没有找到相关文章

最新更新