Fórum RELATORIOS IREPORT + JSF2.0 #408773
24/10/2011
0
Alguem pode me dar uma luz? eu nao estou conseguindo gerar um relatório em pdf...
public void gerarRelatorio() throws IOException {
FacesContext fc = FacesContext.getCurrentInstance();
ServletContext context = (ServletContext) fc.getExternalContext().getContext();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
File relatorioJasper = new File(context.getRealPath(/WEB-INF/reports/relPeticao.jasper));
// parâmetros, se houver
Map parametros = new HashMap();
byte[] bytes = null;
try {
bytes =
JasperRunManager.runReportToPdf(relatorioJasper.getPath(), parametros);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
if (bytes != null && bytes.length > 0) {
// Envia o relatório em formato PDF para o browser
response.setContentType(application/pdf);
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
}
}
João Sobrinho
Curtir tópico
+ 0Posts
24/10/2011
João Sobrinho
Alguem pode me dar uma luz? eu nao estou conseguindo gerar um relatório em pdf...
public void gerarRelatorio() throws IOException {
FacesContext fc = FacesContext.getCurrentInstance();
ServletContext context = (ServletContext) fc.getExternalContext().getContext();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
File relatorioJasper = new File(context.getRealPath(/WEB-INF/reports/relPeticao.jasper));
// parâmetros, se houver
Map parametros = new HashMap();
byte[] bytes = null;
try {
bytes =
JasperRunManager.runReportToPdf(relatorioJasper.getPath(), parametros);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
if (bytes != null && bytes.length > 0) {
// Envia o relatório em formato PDF para o browser
response.setContentType(application/pdf);
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
}
}
Esta dando o seguinte erro:
AVISO: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response
na minha pagina esta assim:
?xml version=1.0 encoding=UTF-8 ?>
<!DOCTYPE composition PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns:ui=http://java.sun.com/jsf/facelets
template=./modeloSistema.xhtml
xmlns:p=http://primefaces.prime.com.tr/ui
xmlns:h=http://java.sun.com/jsf/html>
<ui:composition>
<h:form>
<center><p:commandButton ajax=false action=/index.faces value=Início style=width: 135px/></center>
<p:accordionPanel autoHeight=false>
<p:tab title=Cadastros>
<h:panelGrid columns=1>
<p:commandButton value=Alunos ajax=false action=#{alunoFaces.doListAlunos()} style=width: 135px/>
<p:commandButton value=Professores ajax=false action=#{professorFaces.doListProfessor()} style=width: 135px/>
<p:commandButton value=Petições ajax=false action=#{peticaoFaces.doListPeticao()} style=width: 135px/>
</h:panelGrid>
</p:tab>
<p:tab title=Relatórios>
<h:panelGrid columns=1>
<h:commandButton value=Todas style=width: 135px action=#{peticaoFaces.gerarRelatorio()}/>
<p:commandButton value=Concluídas ajax=false style=width: 135px/>
<p:commandButton value=Hoje ajax=false style=width: 135px/>
<p:commandButton value=Atrasadas ajax=false style=width: 135px/>
</h:panelGrid>
</p:tab>
</p:accordionPanel>
<center><p:commandButton ajax=false action=#{professorFaces.doLogout()} value=Logout style=width: 135px/></center>
</h:form>
</ui:composition>
</html>
Gostei + 0
24/10/2011
João Sobrinho
tudo certo nesse código :D
Abraço
Gostei + 0
24/10/2011
Davi Costa
Assim que possível fechar o chamado.
att Davi
Gostei + 0
09/11/2011
Dyego Carmo
Poderia fechar o chamado ?
Valeu !
Gostei + 0
12/01/2012
Mauricio Silva
Posta o código por gentileza.
Abraço.
Gostei + 0
24/09/2015
Esmeraldina Silva
Tô vendo que vc resolveu seu problema. Vc poderia me ajudar?
Preciso imprimir os dados da minha tabela e não sei por onde começar.
Fiz duas aplicações: Uma cadastrando os dados na tabela e outra com IReport, lendo e imprimindo.
Agora eu preciso imprimir na aplicação que criei de cadastro e não sei como.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)