No, the filter works correctly, the Map <String, FilterMeta> filterBy object is filled with what the user typed. If the filter was not made by the user, the object is not null, however, empty.
Below I will put some code snippets.
Code: Select all
package br.com.iexpertise.common.bean;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.SortMeta;
/**
* Classe com métodos utilitários que auxiliam o desenvolvimento dos formBeans.
*
* @author Rogério Cortina
* @since 17/06/2007
*/
public class JsfBean implements Serializable {
private static final long serialVersionUID = 1L;
public JsfBean() {
super();
}
/**
* Função utilizada para efeito de compatibilidade com as funções já existentes no sistema, evitando assim o refactory de tudo.
*
* @param sortBy
* @return
*/
protected String getSortField(Map<String, SortMeta> sortBy) {
if(sortBy != null && sortBy.isEmpty() == false) {
SortMeta sortM = sortBy.entrySet().stream().findFirst().get().getValue();
return sortM.getField().trim();
}
return null;
}
/**
* Função utilizada para efeito de compatibilidade com as funções já existentes no sistema, evitando assim o refactory de tudo.
*
* @param sortBy
* @return
*/
protected String getSortOrder(Map<String, SortMeta> sortBy) {
if(sortBy != null && sortBy.isEmpty() == false) {
SortMeta sortM = sortBy.entrySet().stream().findFirst().get().getValue();
return sortM.getOrder().toString();
}
return null;
}
/**
* Realiza a conversão do padrão do Primefaces para o nosso padrão, de modo que a camada de negócio não conhecerá a existência de primefaces.
*
* @param sortBy
* @return O primeiro elemento do map é a chave e o segundo é se o mesmo é ASCENDING OU DESCENDING
*/
protected Map<String, String> getSortMap(Map<String, SortMeta> sortBy) {
if(sortBy != null) {
Map<String, String> map = new HashMap<String, String>();
for(String k : sortBy.keySet()) {
map.put(sortBy.get(k).getField(), sortBy.get(k).getOrder().toString());
}
return map;
}
return null;
}
/**
* Realiza a conversão do padrão do Primefaces para o nosso padrão, de modo que a camada de negócio não conhecerá a existência de primefaces.
*
* @param sortBy
* @return O primeiro elemento do map é a chave e o segundo é o valor propriamente dito.
*/
protected Map<String, Object> getFilterMap(Map<String, FilterMeta> filterBy) {
if(filterBy != null) {
Map<String, Object> map = new HashMap<String, Object>();
for(String k : filterBy.keySet()) {
String filterField = filterBy.get(k).getField();
Object filterValue = filterBy.get(k).getFilterValue();
if(filterValue != null) {
map.put(filterField, filterValue);
}
}
return map;
}
return null;
}
}
Code: Select all
lazyModel = new LazyDataModel<DisciplinaVO>() {
List<DisciplinaVO> lista;
@Override
public List<DisciplinaVO> load(int first, int pageSize, Map<String, SortMeta> sortBy, Map<String, FilterMeta> filterBy) {
try {
String sortField = getSortField(sortBy);
String sortOrder = getSortOrder(sortBy);
Map<String, Object> filters = getFilterMap(filterBy);
lista = educacaoBeanDFLocal.listarDisciplinas(firstAux, pageSize, sortField, sortOrder, filters, getClienteSelecionado(), null);
int qtdRows = educacaoBeanDFLocal.listarDisciplinasCount(filters, getClienteSelecionado(), null);
this.setRowCount(qtdRows);
return lista;
} catch (BOValidationException e) {
logger.error("Ocorreu um erro ao tentar realizar a pesquisa de disciplinas: " + e.getMessage());
} catch (BOException e) {
logger.error("Ocorreu um erro ao tentar realizar a pesquisa de disciplinas: " + e.getMessage());
}
return null;
}
@Override
public DisciplinaVO getRowData(String rowKey) {
for (DisciplinaVO aux : lista) {
if (aux.getId().equals(new BigInteger(rowKey))) {
return aux;
}
}
return null;
}
@Override
public String getRowKey(DisciplinaVO disciplina) {
return disciplina.getId().toString();
}
/**
* Corrige o problema da Divisão por Zero
*/
@Override
public void setRowIndex(int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
} else
super.setRowIndex(rowIndex % getPageSize());
}
};