我想创建一个自定义过滤器,但是考虑到两个过滤器同时使用质数(cf {https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml)。
但是,功能过滤器当然只能接收一个过滤器,如下所示
public boolean filterByNote(Object value, Object filter, Locale locale)
因此,我想通过在类中创建两个属性并在方法中使用它们来对此进行反击。但这失败了,因为(我认为原因是)不再调用标签p:selectOneButton的onchange属性。如果我禁止使用p:selectOne ****之一,则它可以正常工作(由于仅应用了一个过滤器,但我可以看到更改,因此未达到预期效果),因此我知道代码的另一部分正在工作。
所以我的问题是,有没有一种方法可以根据需要使用两个过滤器?
@Named
@ViewScoped
public class StatFilter implements Serializable {
private int signNote;
private int note;
private List<Formulaire> formulaireComplete;
private List<Formulaire> formulaireFiltre;
// Filter by Note in a Form
public boolean filterByNote(Object value, Object filter, Locale locale) {
List<Reponse> resp = (List<Reponse>) value;
// if reset, display all
System.out.println("something"); // to check if the function is called
if (signNote == 0)
return true;
// if at list one of the note is ...
// ...superior to the attribute note
else if (signNote == 1) {
for (int i = 0; i < resp.size(); i++) {
if (resp.get(i).getNote() > this.note)
return true;
}
}
// ...inferior to the attribute note
else if (signNote == 2) {
for (int i = 0; i < resp.size(); i++) {
if (resp.get(i).getNote() < this.note)
return true;
}
}
// ...equal to the attribute note
else if (signNote == 3) {
for (int i = 0; i < resp.size(); i++) {
if (resp.get(i).getNote() == this.note)
return true;
}
}
return false;
}
}
<p:column filterBy="#{formulaire.reponses}" headerText="Note"
footerText="equals" filterFunction="#{statFilter.filterByNote}">
<f:facet name="filter">
<p:selectOneButton onchange="PF('formulairesTable').filter()" value="#{statFilter.signNote}">
<f:selectItem itemLabel="Reset" itemValue="0" />
<f:selectItem itemLabel=">" itemValue="1" />
<f:selectItem itemLabel="<" itemValue="2" />
<f:selectItem itemLabel="=" itemValue="3" />
</p:selectOneButton>
<p:selectOneMenu onchange="PF('formulairesTable').filter()" value="#{statFilter.note}">
<f:selectItem itemValue = "1" itemLabel = "1" />
<f:selectItem itemValue = "2" itemLabel = "2" />
<f:selectItem itemValue = "3" itemLabel = "3" />
<f:selectItem itemValue = "4" itemLabel = "4" />
<f:selectItem itemValue = "5" itemLabel = "5" />
<f:selectItem itemValue = "6" itemLabel = "6" />
<f:selectItem itemValue = "7" itemLabel = "7" />
<f:selectItem itemValue = "8" itemLabel = "8" />
<f:selectItem itemValue = "9" itemLabel = "9" />
<f:selectItem itemValue = "10" itemLabel = "10" />
<f:selectItem itemValue = "0" itemLabel = "NA" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{formulaire.responsesToString()}" escape="false" />
</p:column>