Pessoal meu problema é com o método exportReport(); Ao executá-lo o console mostra a seguinte exception (resumidamente). Em seguida vai a classe que executa tal método, o erro como vocês podem perceber é na linha 70, que se trata do tal método exportReport(). Desde já agradeço a atenção de todos!
Caused by: java.lang.ClassCastException: java.io.File cannot be cast to java.lang.String
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:364)
at relatorio.RelatorioUtil.gerarRelatorio(RelatorioUtil.java:70)
at br.com.sistemaDeProtocolo.view.managed.RequerimentoMB.getArquivoRetorno(RequerimentoMB.java:576)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:64)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:168)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
... 26 more
CLASSE:
package relatorio;
import java.io.*;
import java.sql.*;
import java.util.HashMap;
import javax.faces.context.FacesContext;
import javax.naming.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.engine.export.oasis.JROdtExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import com.sun.xml.internal.ws.util.UtilException;
public class RelatorioUtil {
public static final int RELATORIO_PDF = 1;
public static final int RELATORIO_EXCEL = 2;
public static final int RELATORIO_HTML = 3;
public static final int RELATORIO_PLANILHA_OPEN_OFFICE = 4;
public StreamedContent gerarRelatorio(HashMap<String, Object> parametrosRelatorio, String nomeRelatorioJasper, String nomeRelatorioSaida, int tipoRelatorio) throws UtilException {
StreamedContent arquivoRetorno = null;
try{
FacesContext context = FacesContext.getCurrentInstance();
String caminhoRelatorio = context.getExternalContext().getRealPath("relatorios");
String caminhoArquivoJasper = caminhoRelatorio + File.separator + nomeRelatorioJasper + ".jasper";
String caminhoArquivoRelatorio = null;
JasperReport relatorioJasper = (JasperReport) JRLoader.loadObject(caminhoArquivoJasper);
JasperPrint impressoraJasper = JasperFillManager.fillReport(relatorioJasper, parametrosRelatorio, new JREmptyDataSource());
JRExporter tipoArquivoExportado = null;
String extensaoArquivoExportado ="";
File arquivoGerado = null;
switch (tipoRelatorio) {
case RelatorioUtil.RELATORIO_PDF:
tipoArquivoExportado = new JRPdfExporter();
extensaoArquivoExportado = "pdf";
break;
case RelatorioUtil.RELATORIO_HTML:
tipoArquivoExportado = new JRHtmlExporter();
extensaoArquivoExportado = "html";
break;
case RelatorioUtil.RELATORIO_EXCEL:
tipoArquivoExportado = new JRXlsExporter();
extensaoArquivoExportado = "xls";
break;
case RelatorioUtil.RELATORIO_PLANILHA_OPEN_OFFICE:
tipoArquivoExportado = new JROdtExporter();
extensaoArquivoExportado = "ods";
break;
default:
tipoArquivoExportado = new JRPdfExporter();
extensaoArquivoExportado = "pdf";
break;
}
caminhoArquivoRelatorio = caminhoRelatorio + File.separator + nomeRelatorioSaida + "." + extensaoArquivoExportado;
arquivoGerado = new java.io.File(caminhoArquivoRelatorio);
tipoArquivoExportado.setParameter(JRExporterParameter.JASPER_PRINT, impressoraJasper);
tipoArquivoExportado.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, arquivoGerado);
tipoArquivoExportado.exportReport();
arquivoGerado.deleteOnExit();
InputStream conteudoRelatorio = new FileInputStream(arquivoGerado);
arquivoRetorno = new DefaultStreamedContent(conteudoRelatorio, "application/" + extensaoArquivoExportado, nomeRelatorioSaida + "." + extensaoArquivoExportado);
}catch (JRException e) {
throw new UtilException("Não foi possível gerar o relatório.", e);
}catch (FileNotFoundException e) {
throw new UtilException("Arquivo do relatório não encontrado.", e);
}
return arquivoRetorno;
}
}