I found a issue when using DataTable with Filtering. I thought about a work around but did not come up with a solution better than not using the filtering feature. Any ideas appreciated! Thanks.
Problem Description:
I'm using DataTable to present different subsets of database records using a menu for the selection of the subset. This works fine until filtering is used. I boild down the problem to a generic example. Code see below.
Without filtering: (1) loading page with dataset one, (2) an action method (one of the buttons) changes the data in the bean. (3) displays the new data. OK!
With filtering: (1) loading page with dataset one, (2) using the filter (3) filtering works fine (4) an action method changes the data in the bean. (5) nothing happens, the first dataset is still rendered. (6) doing filtering again (7) now the correct dataset is displayed.
Environment:
primefaces-2.2.1, mojarra-2.0.4-FCS, Mac OS X 10.5.8
Code to reproduce the issue:
Code: Select all
<h:body>
<p:panel>
<h:panelGrid columns="1">
<h:form>
<p:commandButton value="Dataset one (Ajax)"
update="sortableDataTable" action="#{testBean.populateDatasetOne}" />
<p:commandButton value="Dataset two (Ajax)"
update="sortableDataTable" action="#{testBean.populateDatasetTwo}" />
<p:commandButton ajax="false" value="Dataset one (no Ajax)"
action="#{testBean.populateDatasetOne}" />
<p:commandButton ajax="false" value="Dataset two (no Ajax)"
action="#{testBean.populateDatasetTwo}" />
<p>Just to see, if ajax works (should NOT change):
#{testBean.currentDataset}</p>
<p:dataTable id="sortableDataTable" var="item"
value="#{testBean.dataset}">
<p:column sortBy="#{item}" filterEvent="keyup" filterBy="#{item}"
filterMatchMode="endsWith"
headerText="Just to see, if ajax works (should change): #{testBean.currentDataset}">
<h:outputText value="#{item}" />
</p:column>
</p:dataTable>
</h:form>
</h:panelGrid>
</p:panel>
</h:body>
Code: Select all
@ManagedBean
@SessionScoped
public class TestBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> dataset;
private String currentDataset;
public TestBean() {
populateDatasetOne();
}
public void setDataset(List<String> dataset) {
this.dataset = dataset;
}
public List<String> getDataset() {
return dataset;
}
public void populateDatasetOne() {
setCurrentDataset("Dataset One");
dataset = new ArrayList<String>();
dataset.add("Dataset One, value One");
dataset.add("Dataset One, value Two");
dataset.add("Dataset One, value Three");
System.out.println("populateDatasetOne() executed");
}
public void populateDatasetTwo() {
setCurrentDataset("Dataset Two");
dataset = new ArrayList<String>();
dataset.add("Dataset Two, value One");
dataset.add("Dataset Two, value Two");
dataset.add("Dataset Two, value Three");
dataset.add("Dataset Two, value Four");
System.out.println("populateDatasetTwo() executed");
}
public void setCurrentDataset(String currentDataset) {
this.currentDataset = currentDataset;
}
public String getCurrentDataset() {
return currentDataset;
}
}
Don