Reputation: 2406
PF 5.0.2, Mojara 2.1.21
I have DataTable with filters and my own autocomplete box for DataTable filtering. If I want to update a DataTable I use "PF('table').filter()", because "normal" update doesn't function. The problem is that "PF('table').filter()" reinitialized "filteredValue"-Backing Bean property list with filterd values from client and ignores the value in my own autocomplete textbox
<p:dataTable filteredValue="#{bean.filtered}"
value="#{bean.values}"
widgetVar="table" >
<p:column filterBy="#{bean.number}">
#{bean.number}
</p:column>
...
</p:dataTable>
<p:autoComplete value="#{bean.textFilter}" />
<p:commandButton value="OK" oncomplete="PF('table').filter();" update="" />
<!-- no update :) -->
So for example before OK was clicked
Before:
bean.filtered= { 1}
bean.values = { 1, 2, 3}
and after OK was clicked it will be changed to
After:
bean.filtered= { 1, 2, 3 }
bean.values = { 1, 2, 3 }
And I want that it remains as before.
EDIT: I've accepted the answer but there are concerns. It does make the job. But primefaces behaves crazy, because set-method doesn't do what PrimeFaces think it should do. So I used filterEvent on DataTable to achieve what I want.
Upvotes: 0
Views: 2389
Reputation: 1221
This is the expected behavior because you are using PF('table').filter()
. What you can do however is add a Boolean
in your ManagedBean, and update it everytime your filtered list setter is called. This way you will have to do:
<p:commandButton value="OK" oncomplete="PF('table').filter();" update=""
actionListener="#{bean.negateFilter}"/>
In your managedBean:
...
private Boolean allowFilter;
...
public void negateFilter(){
this.allowFilter = Boolean.FALSE;
}
...
public void setFiltered(List<Object> filtered){
if (!allowFilter)
this.filtered = filtered;
allowFilter = Boolean.TRUE;
}
...
Then, if allowFilter
is false, it means that you clicked the button for the autocomplete, and your filtered list will not be changed.
Upvotes: 2