Olá Pessoal,
Consegui implementar o exemplo lazyload do primefaces, mas estou com problema no filtro, não filtra nada. Segue abaixo o código.
Obrigado.
public class ParticipLazyList extends LazyDataModel<Participante> {
private List<Participante> datasource;
public ParticipLazyList(List<Participante> datasource) {
this.datasource = datasource;
}
@Override
public Participante getRowData(String rowKey) {
for(Participante participante : datasource) {
if(participante.getCodigo().equals(rowKey))
return participante;
}
return null;
}
@Override
public Object getRowKey(Participante participante) {
return participante.getCodigo();
}
@Override
public List<Participante> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
List<Participante> data = new ArrayList<Participante>();
System.out.println("ParticipLazyList");
System.out.println(sortField);
System.out.println(filters);
//filter
for(Participante participante : datasource) {
System.out.println("filter");
boolean match = true;
for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
String filterValue = filters.get(filterProperty);
String fieldValue = String.valueOf(participante.getClass().getField(filterProperty).get(participante));
if(filterValue == null || fieldValue.startsWith(filterValue)) {
match = true;
}
else {
match = false;
break;
}
} catch(Exception e) {
match = false;
}
}
System.out.println("filter - 000");
System.out.println(participante.getCodigo());
if(match) {
System.out.println("filter - 001");
System.out.println(participante.getCodigo());
data.add(participante);
}
}
Obrigado.