Filtering datatables loaded with ajax.
Posted: 23 Dec 2011, 17:05
I'm having issues with filtering datatables that were not rendered in the initial page load but have been loaded later. This is a very basic example to show what I mean. We are also integrating with spring webflow so the problem could be there but I figured I would post it here to see if you guys have any idea what could be wrong.
PF version: 3.0.RC2 (As far as I can tell it has been present in all 3.X versions but NOT in 2.2.X)
Spring version: 3.0.4.RELEASE
JSF version: 2.0.4
Webflow version: 2.2.1.RELEASE
EDIT: Server is for example tomcat 7.0.12, but I have tried with others also without success.
flow xml:
xhtml code:
Bean code:
Basically, the filtering is not doing anything at all. If you remove the 'rendered' attribute it works, and also if you reload the page when the table is already shown it works.
From, debugging, I've reached the conclusion that something is happening in the DataTable class in this section:
If we put breakpoints here, we can see that when we load the table with ajax, enableFiltering is called and the subsequent isFilteringEnabled calls return true as expected. However, in the next request that is sent from the 'onkeyup' filtering event, isFilteringEnabled returns false as it can't find any 'filtering' property in the state helper. In the case where the table is rendered with the intial page request, the filtering request correctly returns true and the table is filtered. The likely conclusion from this is that the problem is in the webflow persistence, but I'm puzzled by the fact that it was working fine in 2.2.1.
If you need any additional information about our configuration don't hesitate to ask.
PF version: 3.0.RC2 (As far as I can tell it has been present in all 3.X versions but NOT in 2.2.X)
Spring version: 3.0.4.RELEASE
JSF version: 2.0.4
Webflow version: 2.2.1.RELEASE
EDIT: Server is for example tomcat 7.0.12, but I have tried with others also without success.
flow xml:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<view-state id="start" view="sandbox.xhtml">
<on-entry>
<evaluate expression="new org.mypackage.SandboxBean()" result="flowScope.sandboxBean"/>
</on-entry>
</view-state>
</flow>
Code: Select all
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ap="http://java.sun.com/jsf/composite/ap"
xmlns:dyn="http://java.sun.com/jsf/composite/dyn">
<h:head>
<ui:insert name="headIncludes" />
<link type="text/css" rel="stylesheet" href="../styles/ap-base.css" />
</h:head>
<h:body>
<h:form id="mainForm">
<p:commandLink value="Show table" actionListener="#{sandboxBean.setShowTable(true)}" update=":mainForm" />
<p:dataTable rendered="#{sandboxBean.showTable}" var="rowVar" value="#{sandboxBean.firstList}">
<p:column filterBy="#{rowVar}" filterMatchMode="contains">
<h:outputText value="#{rowVar}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Code: Select all
package org.mypackage;
import java.io.Serializable;
import java.util.ArrayList;
public class SandboxBean implements Serializable {
private ArrayList<String> firstList;
private boolean showTable;
public SandboxBean() {
firstList = new ArrayList<String>();
firstList.add("TestString");
}
public ArrayList<String> getFirstList() {
return firstList;
}
public boolean isShowTable() {
return showTable;
}
public void setShowTable(boolean showTable) {
this.showTable = showTable;
}
}
From, debugging, I've reached the conclusion that something is happening in the DataTable class in this section:
Code: Select all
public boolean isFilteringEnabled() {
Object value = getStateHelper().get("filtering");
return value == null ? false : true;
}
public void enableFiltering() {
getStateHelper().put("filtering", true);
}
If you need any additional information about our configuration don't hesitate to ask.