答案 0 :(得分:1)
要自定义过滤器,您必须将filterMatchMode属性定义为“ custom”,并使用在Primefaces documentation(466或470)中定义的定义javascript函数的filterFunction =“ myFilter”属性。 / p>
在这种情况下,我将自定义过滤器以忽略包含的重音符号和特殊字符(与filterMatchMode =“ contains”相同)
file.xhtml
<p:selectOneListbox filter="true" filterMatchMode="custom" filterFunction="contains" value="#{controllerBean.id}">
<f:selectItems value="#{controllerBean.list}" var="item" itemLabel="#{item.value}" itemValue="#{item.id}" />
</p:selectOneListbox>
file.js
function contains(itemLabel, filterValue) {
return itemLabel.includes(filterValue) || specialCharacters(itemLabel).includes(filterValue);
}
function specialCharacters(input){
var c=input.toLowerCase();
c = c.replace(new RegExp("\\s", 'g'),"");
c = c.replace(new RegExp("[àáâãäå]", 'g'),"a");
c = c.replace(new RegExp("æ", 'g'),"ae");
c = c.replace(new RegExp("ç", 'g'),"c");
c = c.replace(new RegExp("[èéêë]", 'g'),"e");
c = c.replace(new RegExp("[ìíîï]", 'g'),"i");
c = c.replace(new RegExp("[òóôõö]", 'g'),"o");
c = c.replace(new RegExp("œ", 'g'),"oe");
c = c.replace(new RegExp("[ùúûü]", 'g'),"u");
c = c.replace(new RegExp("[ýÿ]", 'g'),"y");
return c;
}