Am using JDK 1.8 and JSF Primefaces 7 to create a JSF DataTable which needs to have sorting and filtering functionality.
My code hits an external datasource which marshals my Product Pojos from an external JSON feed.
My table populates correctly and I am able to sort all my columns.
When I click on a specific column's header, I am able to utilize the filtering capability by viewing a single row (after entering in the data for a specific row).
However, when I click out of the specific column's header and try sorting any of my columns, the table's contents become "cleared" (you can't see anything inside the rows or columns, but the length of the rows remains visible).
JSF Primefaces dependencies:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>7.0.3</version>
</dependency>
All the UI functionality seems to work by setting up my table declaratively via a custom XHTML file:
<!DOCTYPE html 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:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
>
<p:dataTable id="data"
var="entityList"
value="#{myView.product.entityList}"
styleClass="auto-table"
resizableColumns="true"
resizeMode="expand"
paginator="true"
rows="25"
paginatorAlwaysVisible="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100"
reflow="true"
sortMode="single">
<p:column headerText="product_id"
sortBy="#{entityList.product_id}"
filterBy="#{entityList.product_id}"
filterMatchMode="contains">
<h:outputText value="#{entityList.product_id}"/>
</p:column>
<p:column headerText="description"
filterBy="#{entityList.description}"
filterMatchMode="contains">
<h:outputText value="#{entityList.description}"/>
</p:column>
<p:column headerText="price"
filterBy="#{entityList.price}"
filterMatchMode="contains">
<h:outputText value="#{entityList.price}"/>
</p:column>
</p:dataTable>
</html>
MyView.java:
@Named
@ViewScoped
public class MyView implements Serializable {
private Product product;
@PostConstruct
public void init() {
}
public void getProduct() {
// This method just hits an external datasource
// and marshals the JSON w/ my Product POJO.
}
}
Product:
@Data
public class Product {
private List<Entity> entityList;
@Data
public static class Entity {
private String productId;
private String description;
private String price;
// Getters and Setters not listed because of Lombok usage.
}
}
Why does the table become empty (with the rows present / viewable) after I click out of the filtering and then trying to resort?
It happens after trying to sort on a particular column's header...
Is there a helper class that I need to write or is it simply finding a particular XTML attribute that I need to insert inside my <p:column/>
tag?