I'm trying to add a filter in my datatable, but it's not working. I also tried with global filter but the result was the same. I need my datable get filtered by this 2 basic columns (nucleo and localizacao).
Below my Bean and also the reportes.xhtml
#reportes.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<meta http-equiv="Refresh" content="500; url=reportes.xhtml"></meta>
<title>Reportes Pendentes</title>
<link rel='shortcut icon' href="resources/images/notepad.ico" />
</h:head>
<h:body>
<style type="text/css">
.vermelho {
background-color: #FF6347;
}
.azul {
background-color: #BFEFFF;
}
</style>
<table id="tabelaCabecalhoInicio" width="100%">
<td><p:graphicImage id="teste1"
style="margin-right:auto;margin-left:auto;"
value="/resources/images/schmersal1.png" height="95px" width="264px"
styleClass="teste" /></td>
<td style="text-align: rigth"><h1>Reportes Schmersal</h1></td>
</table>
<p:panel id="tabela">
<f:facet name="header" style="text-align:center" width="10"> Reportes Pendentes </f:facet>
<p:dataTable id="teste" var="reporte"
value="#{reporteBean.listaReportes}" widgetVar="reportesTable"
paginator="false" resizableColumns="true" scrollable="true"
scrollWidth="95%" scrollHeight="400"
rowStyleClass="#{reporte.erro ? 'vermelho' : 'azul'}"
sortBy="#{reporte.erro}" filteredValue="#{reporteBean.listaReportes}" >
<p:column width="15">
<f:facet name="header">#</f:facet>
<h:form style="text-align:center;font-size:12px;text-align:left">#{rowCounter.row} </h:form>
</p:column>
<p:column width="80">
<f:facet name="header">Ignorar</f:facet>
<p:commandLink style="background-color:#2E366A;color:white"
value="Ignorar" type="button"
action="#{reporteBean.ignorarReporte(reporte)}" immediate="true"
onclick="window.location.reload()" />
</p:column>
<p:column sortBy="#{reporte.ordemProducao.id}" width="45">
<f:facet name="header">Op</f:facet>
<h:form style="text-align:center;font-size:11px;text-align:left">#{reporte.ordemProducao.id}</h:form>
</p:column>
<p:column sortBy="#{reporte.ordemProducao.codItem}" width="100">
<f:facet name="header">Item</f:facet>
<h:form style="text-align:center;font-size:11px;text-align:left">#{reporte.ordemProducao.codItem}</h:form>
</p:column>
<p:column sortBy="#{reporte.ordemProducao.descItem}" width="130">
<f:facet name="header">Descrição </f:facet>
<h:form style="text-align:center;font-size:10px">#{reporte.ordemProducao.descItem}</h:form>
</p:column>
<p:column sortBy="#{reporte.qtde}" width="52">
<f:facet name="header">Qtd</f:facet>
<h:form style="text-align:center;font-size:15px;text-align:center">#{reporte.qtde}</h:form>
</p:column>
<p:column sortBy="#{reporte.ordemProducao.localizacao}" width="100" filterBy="#{reporte.ordemProducao.localizacao}">
<f:facet name="header">Localização </f:facet>
<h:form style="text-align:center;font-size:12px">#{reporte.ordemProducao.localizacao}</h:form>
</p:column>
<p:column sortBy="#{reporte.ordemProducao.deposito}" width="80">
<f:facet name="header">Depósito </f:facet>
<h:form style="text-align:center;font-size:12px">#{reporte.ordemProducao.deposito}</h:form>
</p:column>
<p:column
sortBy="#{reporte.ordemProducao.complementoReportes.planejador}"
width="100">
<f:facet name="header">Planejador </f:facet>
<h:form style="text-align:center;font-size:12px">#{reporte.ordemProducao.complementoReportes.planejador}</h:form>
</p:column>
<p:column
sortBy="#{reporte.ordemProducao.complementoReportes.nucleo}" filterBy="#{reporte.ordemProducao.localizacao}"
width="100" filterMatchMode="exact" >
<f:facet name="header">Nucleo </f:facet>
<h:form style="text-align:center;font-size:12px">#{reporte.ordemProducao.complementoReportes.nucleo}</h:form>
</p:column>
<p:column sortBy="#{reporte.operacao.centroCusto.id}"
paginator="false" width="50">
<f:facet name="header">CC</f:facet>
<h:form style="text-align:center;font-size:12px;text-align:left">#{reporte.operacao.centroCusto.id} </h:form>
</p:column>
<p:column sortBy="#{reporte.operacao.centroCusto.descricao}"
paginator="false" width="150">
<f:facet name="header">Centro Custo</f:facet>
<h:form style="text-align:center;font-size:12px;text-align:left">#{reporte.operacao.centroCusto.descricao} </h:form>
</p:column>
<p:column sortBy="#{reporte.operador.nome}" paginator="false"
width="230">
<f:facet name="header">Operador</f:facet>
<h:form style="text-align:center;font-size:12px;text-align:left">#{reporte.operador.nome} </h:form>
</p:column>
<p:column sortBy="#{reporte.dthrInclusao}" width="96">
<f:facet name="header">Inclusão</f:facet>
<h:form style="text-align:center;font-size:11px">#{reporte.dthrInclusao}</h:form>
</p:column>
</p:dataTable>
</p:panel>
<p:panel>
<p:column>
<h:form style="margin:center">
<p:clock pattern="dd/MM/yyyy - HH:mm:ss" />
</h:form>
</p:column>
</p:panel>
<h:form id="form">
<h:panelGrid columns="1" cellpadding="5">
</h:panelGrid>
</h:form>
</h:body>
</html>
#ReporteBean
package br.com.schmersal.reportes.bean;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import org.hibernate.ObjectNotFoundException;
import org.joda.time.LocalDateTime;
import br.com.schmersal.reportes.dao.ReporteDao;
import br.com.schmersal.svm.apontatouch.hibernate.HibernateUtilSQL;
import br.com.schmersal.svm.apontatouch.modelo.Reporte;
@ViewScoped
@ManagedBean(name = "reporteBean")
public class ReporteBean implements Serializable {
private List<Reporte> listaReportes = new ArrayList<Reporte>();
private List<Reporte> listaReportesN1 = new ArrayList<Reporte>();
private List<Reporte> listaFiltro;
private ReporteDao dao;
@ManagedProperty(value = "#{loginBean}")
private LoginBean login;
// public ReporteBean(){
//
// System.out.println("erro");
//
// }
public ReporteBean() {
}
@PostConstruct
public void init() {
if (this.login != null && this.login.getOperador() != null && this.login.getOperador().getPaginaReportes()) {
dao = new ReporteDao(new HibernateUtilSQL());
try {
listaReportes = dao.getLista(null);
} catch (ObjectNotFoundException e) {
try {
atualizaPlanejadoresItens();
try {
listaReportes = dao.getLista(null);
} catch (Exception e1) {
e1.printStackTrace();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public void busca(Long idCentroCusto) {
dao = new ReporteDao(new HibernateUtilSQL());
try {
listaFiltro = dao.getLista(idCentroCusto);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Reporte> getListaReportes() throws Exception {
// TODO tratar erro ao bater no brz-app27 e mudar local da chamada
if (listaReportes == null) {
try {
atualizaPlanejadoresItens();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return listaReportes;
}
public List<Reporte> getListaReportesN1() throws Exception {
dao.getListaN1(1);
if (listaReportes == null) {
try {
atualizaPlanejadoresItens();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return listaReportes;
}
public void setListaReportes(List<Reporte> listaReportes) {
this.listaReportes = listaReportes;
}
//
// public void ignorarReporte(Repo){
//
// ReporteDaoTeste dao = new ReporteDaoTeste(new HibernateUtilSQL());
// reporte.setIgnorar(true);
// dao.update(reporte);
//
// }
public void limpar() {
try {
listaReportes = dao.getLista(null);
} catch (Exception e) {
e.printStackTrace();
}
}
public void ignorarReporte(Reporte reporte) {
reporte.setIgnorar(true);
reporte.setDthrUltimaTentativa(new LocalDateTime());
reporte.setOperadorIgnorar(login.getOperador());
try {
dao.update(reporte);
} catch (Exception e) {
e.printStackTrace();
}
}
public void atualizaPlanejadoresItens() throws IOException {
BufferedReader readerChamada;
String line;
StringBuffer responseContentChamada = new StringBuffer();
String urlFinal = "http://brz-ti27:8585/telaReportes/integraCompleta";
// System.out.println(urlFinal);
URL urlConsulta = new URL(urlFinal);
HttpURLConnection conexaoConsulta = (HttpURLConnection) urlConsulta.openConnection();
conexaoConsulta.setRequestMethod("GET");
conexaoConsulta.setConnectTimeout(50000);
conexaoConsulta.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conexaoConsulta.setRequestProperty("Accept", "application/json");
conexaoConsulta.setDoOutput(true);
conexaoConsulta.setDoInput(true);
int status = conexaoConsulta.getResponseCode();
if (status == 401) {
// lançar excecao
}
if (status > 299) {
readerChamada = new BufferedReader(new InputStreamReader(conexaoConsulta.getErrorStream()));
while ((line = readerChamada.readLine()) != null) {
responseContentChamada.append(line);
}
// readerChamada.close();
} else {
readerChamada = new BufferedReader(new InputStreamReader(conexaoConsulta.getInputStream()));
while ((line = readerChamada.readLine()) != null) {
responseContentChamada.append(line);
}
// readerChamada.close();
}
/*
* GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson =
* gsonBuilder.create(); JSONObject jsonObject = new
* JSONObject(responseContentChamada.toString());
*
* Object fromJson = gson.fromJson(jsonObject.toString(), Object.class);
*
* // System.out.println(jsonObject);
*
* System.out.println(fromJson);
*/
}
public LoginBean getLogin() {
return login;
}
public void setLogin(LoginBean login) {
this.login = login;
}
public List<Reporte> getListaFiltro() {
return listaFiltro;
}
public void setListaFiltro(List<Reporte> listaFiltro) {
this.listaFiltro = listaFiltro;
}
public ReporteDao getDao() {
return dao;
}
public void setDao(ReporteDao dao) {
this.dao = dao;
}
public void setListaReportesN1(List<Reporte> listaReportesN1) {
this.listaReportesN1 = listaReportesN1;
}
}
I was just expecting to have the values filtered by nucleo or by localizacao