However, I found that all the "filterValues" are in LowerCase letter no matter what have been inputted at the filter textbox.
After looking into the PrimeFaces Source Code, I found that it arises from the following line at the "org.primefaces.component.datatable.DataHelper.decodeFilterRequest()":
Code: Select all
String filterValue = params.get(filterName).toLowerCase();
Code: Select all
void decodeFilterRequest(FacesContext context, DataTable table) {
String clientId = table.getClientId(context);
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
//Reset state
table.setFirst(0);
table.setPage(1);
if(table.isLazy()) {
Map<String,String> filters = new HashMap<String, String>();
Map<String,Column> filterMap = table.getFilterMap();
for(String filterName : filterMap.keySet()) {
Column column = filterMap.get(filterName);
String filterValue = params.get(filterName).toLowerCase();
if(!isValueBlank(filterValue)) {
String filterField = resolveField(column.getValueExpression("filterBy"));
filters.put(filterField, filterValue);
}
}
table.setFilters(filters);
table.loadLazyData();
//Metadata for callback
if(table.isPaginator()) {
RequestContext.getCurrentInstance().addCallbackParam("totalRecords", table.getRowCount());
}
}
else {
Map<String,Column> filterMap = table.getFilterMap();
List filteredData = new ArrayList();
table.setValue(null); //Always work with user data
String globalFilter = params.get(clientId + UINamingContainer.getSeparatorChar(context) + "globalFilter");
boolean hasGlobalFilter = !isValueBlank(globalFilter);
if(hasGlobalFilter) {
globalFilter = globalFilter.toLowerCase();
}
for(int i = 0; i < table.getRowCount(); i++) {
table.setRowIndex(i);
boolean localMatch = true;
boolean globalMatch = false;
for(String filterName : filterMap.keySet()) {
Column column = filterMap.get(filterName);
String columnFilter = params.get(filterName).toLowerCase();
String columnValue = String.valueOf(column.getValueExpression("filterBy").getValue(context.getELContext()));
if(hasGlobalFilter && !globalMatch) {
if(columnValue != null && columnValue.toLowerCase().contains(globalFilter))
globalMatch = true;
}
if(isValueBlank(columnFilter)) {
localMatch = true;
}
else if(columnValue == null || !column.getFilterConstraint().applies(columnValue.toLowerCase(), columnFilter)) {
localMatch = false;
break;
}
}
boolean matches = localMatch;
if(hasGlobalFilter) {
matches = localMatch && globalMatch;
}
if(matches) {
filteredData.add(table.getRowData());
}
}
table.setRowIndex(-1); //cleanup
table.setValue(filteredData);
//Metadata for callback
if(table.isPaginator()) {
RequestContext.getCurrentInstance().addCallbackParam("totalRecords", filteredData.size());
}
}
}
Here's the test code:
Code: Select all
public LazyDataModel<MyEntity> getMyDatatableValue()
{
if( myDatatableValue == null )
{
myDatatableValue = new LazyDataModel<MyEntity>()
{
public List<MyEntity> load( int first, int pageSize, String sortField, boolean sortOrder,
Map<String, String> filters )
{
// all FilterValues, "filters", here are always been converted to LowerCase!!?
return getMyEntityDbService().findAll( first, pageSize, sortField, sortOrder, filters );
}
};
}
myDatatableValue.setRowCount( getMyEntityService().findAllRowCount() );
return myDatatableValue;
}
Any way to preserve original text lettercase for filtering to be picked up at the back-end bean?