DataTable update issue after filtering

UI Components for JSF
Post Reply
Don Esteban
Posts: 3
Joined: 01 Mar 2011, 13:35

01 Mar 2011, 14:49

Hi all,

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;
	}

}
Regards
Don

Don Esteban
Posts: 3
Joined: 01 Mar 2011, 13:35

03 Mar 2011, 13:46

Hello again,

I'll try to bring my question below to the agenda again. I would apreciate any feedback, even telling me, that their is no known work around or that I'm doing something very stupid. I do not believe, that I'm the only person facing this issue. It seems to be a usual use case and I'll need that functionality many times throughout the application.

Regards
Don

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests