omnifaces / optimusfaces

Utility library for OmniFaces + PrimeFaces combined

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClassCastException inside LazyPagedDataModel.getFilterValue

adets opened this issue · comments

commented

Hi!

IMHO there is a tiny (but very problematic) bug inside this method due to filterMeta.getFilterValue() cast to String. Filter value is not necessary a String - it can be object of any class. Or it can be even a collection of objects (in case a custom filter facet is used with, say, p:selectCheckboxMenu). Model handles non-string filters, including collections, just fine - if not for this unfortunate cast.

Assuming global filter must be string:

diff --git a/src/main/java/org/omnifaces/optimusfaces/model/LazyPagedDataModel.java b/src/main/java/org/omnifaces/optimusfaces/model/LazyPagedDataModel.java
index 3a32bc6..5534d57 100644
--- a/src/main/java/org/omnifaces/optimusfaces/model/LazyPagedDataModel.java
+++ b/src/main/java/org/omnifaces/optimusfaces/model/LazyPagedDataModel.java
@@ -315,7 +315,7 @@
 	}
 
 	protected String processGlobalFilter(FacesContext context, DataTable table, Map<String, FilterMeta> filterBy) {
-		String globalFilter = getFilterValue(filterBy, GLOBAL_FILTER);
+		String globalFilter = (String) getFilterValue(filterBy, GLOBAL_FILTER);
 
 		if (globalFilter != null) {
 			globalFilter = globalFilter.trim();
@@ -328,9 +328,9 @@
 		return isEmpty(globalFilter) ? null : globalFilter;
 	}
 
-	private String getFilterValue(Map<String, FilterMeta> filterBy, String field) {
+	private Object getFilterValue(Map<String, FilterMeta> filterBy, String field) {
 		FilterMeta filterMeta = filterBy.get(field);
-		return (filterMeta == null) ? null : (String) filterMeta.getFilterValue();
+		return (filterMeta == null) ? null : filterMeta.getFilterValue();
 	}
 
 	private String getFilterParameterName(FacesContext context, DataTable table, String field) {