richfaces过滤日期列

时间:2013-03-31 15:42:46

标签: java jsf richfaces

我为包含String值的列创建了过滤器。有用。但是同样的方法不起作用 为了约会。当我选择某个日期时,它不会过滤任何内容,但是当我在过滤器中选择空值时,它会显示所有日期。所以它有效,但日期有问题:(

有字符串值的代码:

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

1 个答案:

答案 0 :(得分:1)

您似乎尝试使用Date进行过滤的方法按String进行过滤:

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