本文介绍了Primefaces selectCheckBoxMenu filter ="custom"财产不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用primefaces 3.5,并且我想使用selectCheckBoxMenu组件.实际上,我处理了此组件的许多属性,但是我拥有大量列表,并且我愿意使用懒惰获取此列表,并且此组件不包含懒惰属性.因此,我决定使用filter ="custom"和filterFunction属性来过滤列表.

I'm using primefaces 3.5 and i want to use selectCheckBoxMenu component. Actually, i handle lots of property of this component, but i have huge list and i am willing to get this list with lazy and this component doesn't include lazy property. Therefore, i decided to filter my list by using filter="custom" and filterFunction property.

这是我的代码:

<p:selectCheckboxMenu id="personelListesiCheckBoxId"
                                      value="#{gidenKutusuController.secilenKullaniciListesi}"
                                      converter="#{personelConverter}"
                                      label="#{gidenKutusuController.personelLabel}"
                                      filter="true"
                                      filterMatchMode="custom"
                                      filterFunction="customFilter"
                                      panelStyle="width:220px">
                    <p:ajax event="toggleSelect" process="@this"
                            onstart="personelGetir();"/>
                    <p:ajax event="change"
                            process="@this"
                            listener="#{gidenKutusuController.listenerPersonelSecildi()}"
                            update="@this"/>
                    <f:selectItems value="#{gidenKutusuController.personelListesi}" var="personel"
                                   itemLabel="#{personel.adi} #{personel.soyadi}"
                                   itemValue="#{personel}"/>
                </p:selectCheckboxMenu>
                <p:remoteCommand process="@this"
                                 action="#{gidenKutusuController.listenerPersonelSecildi()}"
                                 name="personelGetir"
                                 update=":form:personelListesiCheckBoxId"/>
                <p:remoteCommand process="@this"
                                 action="#{gidenKutusuController.listenerPersonelListesiLazyGetirByFilter()}"
                                 name="personelListesiniGetirByFilter"
                                 update="@this"/>

和此Java脚本代码:

and this java script code :

<script type="text/javascript">
    function customFilter(itemLabel, filterValue) {
        personelListesiniGetirByFilter({fv: filterValue});
    }
</script>

我想在用户输入过滤器时执行此操作,我获取该值并使用该值查询数据库并获取列表并将列表设置为selectCheckBoxMenu组件.我使用filterMatchMode ="custom"和filterFunction ="customFilter"来获取类型化的值,然后通常在用户键入时必须调用customFilter java脚本函数,它不起作用.

I want to do that when the user type into filter, i get that value and query database with that value and get list and set the list to the selectCheckBoxMenu component.To do that,i use filterMatchMode="custom" and filterFunction="customFilter" in order to get the typed value, then normally when the user typed, customFilter java script function must be called , it is not working.

我不知道如何解决问题.请帮助我.

I don't know how to solve the problem. Please help me.

这是primefaces 3.5指南

Here is the primefaces 3.5 guide

<p:selectCheckboxMenu value="#{bean.selectedOptions}" label="Movies"
             filterMatchMode="custom" filterFunction="customFilter">
             <f:selectItems value="#{bean.options}" />
</p:selectCheckboxMenu>


function customFilter(itemLabel, filterValue) {
     //return true to accept and false to reject
}

推荐答案

您的代码不起作用的原因是filterFunction期望在您的bean中实现一个函数:nameOfYourCustomFunction(对象值,对象过滤器,语言环境区域设置).例如,看一下如何实现PrimeFaces"ContainsFilterConstraint.java"类.另外,请查看我在此问题中的答案,以使您的selectCheckboxMenu过滤器真正起作用: https://stackoverflow.com/a/34383835/4145964

The reason your code does not work is that the filterFunction expects a function implemented in your bean: nameOfYourCustomFunction(Object value, Object filter, Locale locale). For example, take a look at how PrimeFaces "ContainsFilterConstraint.java" Class is implemented. Also, look at my answer in this question, in order to get your selectCheckboxMenu Filter to actually work:https://stackoverflow.com/a/34383835/4145964

这篇关于Primefaces selectCheckBoxMenu filter ="custom"财产不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:00