Datatable: filter not working with column created with JSTL
See original GitHub issueDescribe the defect Datatable filter is not functional if a column created by c:foreach since commit: https://github.com/primefaces/primefaces/commit/67f5999bbcc95691c7d9a12030debbd7da58b93e
Reproducer PrimeFaces-Test zip: primefaces-test.zip
How to run: extract the zip file and use command mvn clean jetty:run, after jetty server is launched. Go to the URL: http://localhost:8080/primefaces-test/datatable.xhtml
Code:
datatable.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite = "http://java.sun.com/jsf/composite"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:cc = "http://java.sun.com/jsf/composite/components">
<h:head>
<title>PrimeFaces Test</title>
<h:outputScript name="test.js" />
</h:head>
<h:body>
<h1>#{testView.testString}</h1>
<h:form id="frmTest">
<p:dataTable var="car" value="#{dtBasicView.cars}">
<p:column headerText="Id" filterBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year" filterBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand" filterBy="#{car.brand}">
<h:outputText value="#{car.brand}" />
</p:column>
<c:forEach begin="0" end="2">
<p:column headerText="Color" filterBy="#{car.color}">
<h:outputText value="#{car.color}" />
</p:column>
</c:forEach>
</p:dataTable>
</h:form>
</h:body>
</html>
BasicView.java
package org.primefaces.test;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named("dtBasicView")
@ViewScoped
public class BasicView implements Serializable {
/**
*
*/
private static final long serialVersionUID = 9024342410196834191L;
private List<Car> cars;
@Inject
private CarService service;
@PostConstruct
public void init() {
cars = service.createCars(10);
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
}
Car.java
/*
* Copyright 2009-2014 PrimeTek.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.test;
import java.io.Serializable;
public class Car implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1460567576542303442L;
public String id;
public String brand;
public int year;
public String color;
public int price;
public boolean sold;
public Car() {
}
public Car(String id, String brand, int year, String color) {
this.id = id;
this.brand = brand;
this.year = year;
this.color = color;
}
public Car(String id, String brand, int year, String color, int price, boolean sold) {
this.id = id;
this.brand = brand;
this.year = year;
this.color = color;
this.price = price;
this.sold = sold;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public boolean isSold() {
return sold;
}
public void setSold(boolean sold) {
this.sold = sold;
}
@Override
public int hashCode() {
int hash = 7;
hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Car other = (Car) obj;
if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
return false;
}
return true;
}
}
CarService.java
package org.primefaces.test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
@Named
@ApplicationScoped
public class CarService {
private final static String[] colors;
private final static String[] brands;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
brands = new String[10];
brands[0] = "BMW";
brands[1] = "Mercedes";
brands[2] = "Volvo";
brands[3] = "Audi";
brands[4] = "Renault";
brands[5] = "Fiat";
brands[6] = "Volkswagen";
brands[7] = "Honda";
brands[8] = "Jaguar";
brands[9] = "Ford";
}
public List<Car> createCars(int size) {
List<Car> list = new ArrayList<Car>();
for (int i = 0; i < size; i++) {
list.add(new Car(getRandomId(), getRandomBrand(), getRandomYear(), getRandomColor(),
getRandomPrice(), getRandomSoldState()));
}
return list;
}
private String getRandomId() {
return UUID.randomUUID().toString().substring(0, 8);
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomBrand() {
return brands[(int) (Math.random() * 10)];
}
private int getRandomPrice() {
return (int) (Math.random() * 100000);
}
private boolean getRandomSoldState() {
return (Math.random() > 0.5) ? true : false;
}
public List<String> getColors() {
return Arrays.asList(colors);
}
public List<String> getBrands() {
return Arrays.asList(brands);
}
}
Environment:
- PF Version: 8.0 SNAPSHOT+
- JSF + version: any
- Affected browsers: ALL_
To Reproduce Steps to reproduce the behavior:
-
Enter value to the filter (e.g. Black under the color column):
-
Filter is not functional
Expected behavior
If we checkout any commit before: https://github.com/primefaces/primefaces/commit/67f5999bbcc95691c7d9a12030debbd7da58b93e. For example: https://github.com/primefaces/primefaces/commit/9e79f12a7660877fb8923f5ae1f67150d10fe32d which is the direct parent commit.
In Primefaces Repo:
git checkout 9e79f12a7660877fb8923f5ae1f67150d10fe32d
mvn clean install
In Primefaces-Test Repo, go to http://localhost:8080/primefaces-test/datatable.xhtml after
mvn clean jetty:run
Please verify https://github.com/primefaces/primefaces/commit/67f5999bbcc95691c7d9a12030debbd7da58b93e as it is the commit to introduce regression.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
The pending PR won’t fix it, I’m waiting for that PR to be merged first before I can submit the new one (for #6402, which I already started to work on)
Re: https://github.com/primefaces/primefaces/issues/6421#issuecomment-712004694
Not necessarily true:), that’s a simplified sample to expose this bug. We could use
ui:param
to inject index which can be dynamically resolved for displaying different columns, but it would be null currently.Thanks @Rapster. By the time the new PR is created and merged. This issue should be resolved.