We have a lot of grids in our Vaadin app, every one of them has some filters on string columns.
Recently we noticed that not all of them are working. There are no errors in the log, no exceptions, no nothing.
We have one method for adding all the filters to string columns in the whole app, it adds a text field to a HeaderRow of a grid with specific listener:
public <T> void addFilterToSpecificStringColumn(ListDataProvider<T> dataProvider, HeaderRow filterRow, String columnName, FilterObject filter) {
TextField filterField = new TextField();
filterField.setValueChangeMode(ValueChangeMode.EAGER);
filterField.addValueChangeListener(event -> {
filter.setCorrectFieldByName(columnName, event.getValue());
dataProvider.refreshAll();
});
filterRow.getCell(this.getColumnByKey(columnName)).setComponent(filterField);
}
This is how we add the filter:
dataProvider.setFilter(filterObject::searchForOffer);
and this is a basic filter method of FilterObject added to DataProvider by setFilter() method and seems like this is not always working:
public boolean searchForOffer(Offer offer) {
return name.length() == 0 || StringUtils.containsIgnoreCase(String.valueOf(offer.getName()), name);
}
In normal case the dataProvider.refreshAll() called in the text field listener would trigger the searchForOffer() method which goes through data provider list elements one by one and returns offers which meet the filter condition (name in this case). This basically stopped working in some grids and i am not sure why.
Listener is called, i am able to debug it, dataProvider.refreshAll() is called but it never calls the filter method which is the case in other grids.
What could be the problem here? Ive checked and the dataProvider.getItems() is the same instance of list that is set when invoking grid.setItems().
We are using Vaadin 14(java only), Java 11.
Ok, I asked here because I spent almost 5 hours trying to figure out what is wrong. Turns out another dev added a grid.setItems()
(which creates a new data provider) where he passed a new instance of a list with the same elements because we do have other threads updating grids.
I felt hopeless at some point, but the second I posted the question I found what the problem was.