Erro ao gerar relatorio com IReport + JSF na Web

Não é “chamar 2 vezes” era porque eles chamavam ao mesmo tempo, pois havia uma requisição e o primefaces interceptava e utilizava esse metodo (tambem).

Sobre o erro no log, você configurou o log pra mostrar tudo?

quando ele cai no catch seu log está parecido com isso: LOG.error(e.getMessage(), e);

isso fará com que apareça no log tudo o que diz respeito ao erro, podendo te ajudar a solucionar.

Não configurei Log, bem, minha experiência com Web é bem precária, é a primeira vez que estou subindo um projeto na Web …
Mas, me diz uma coisa, dessa forma ele não teria que exibir os Erros:

[code]} catch (JRException e) {
e.printStackTrace();

}catch (IOException e) {
e.printStackTrace();
}[/code]

Pelo menos no integrator, só se monta o log do sistema se você tiver um log mesmo.

Pegue esse exemplo: http://imasters.com.br/artigo/23971/java/usando-log4j-em-projetos-java/

Vai te ajudar muito ter o real erro de sua aplicação.

Vlw meu querido … Vou ler a respeito e adaptar ao projeto … Solucionando posto aqui …

Diego,
Conseguiu resolver esse problema? Estou passando por isso tb.

Abraços

Olá amigo, eu tava ajudando ele nesse, coloca teu pro e teu erro aew. Abração !!!

É exatamente o mesmo problema…igual sem tirar nem por.

Eu rodo o relatório quando estou testando aqui em casa, e quando subo para a Integrator dá esse erro.
Não tem nada no log. Nada.

Não sei oq fazer, já tentei de tudo…

Beleza, me manda tua implementação do relatorio.

Vc ta abrindo ele no navegador ou pelo Jasper View?

Estou abrindo pelo navegador, direto da hospedagem.

<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="LancamentoNotas" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f9d1de44-8e01-4358-bedb-577dd99041bf"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <parameter name="usuarioDocumento" class="java.lang.String" isForPrompting="false"/> <parameter name="usuarioNome" class="java.lang.String" isForPrompting="false"/> <queryString> <![CDATA[]]> </queryString> <field name="matricula" class="java.lang.String"> <fieldDescription><![CDATA[aluno.matricula]]></fieldDescription> </field> <field name="nome" class="java.lang.String"> <fieldDescription><![CDATA[aluno.nome]]></fieldDescription> </field> <field name="serieNome" class="java.lang.String"> <fieldDescription><![CDATA[aluno.serie.nome]]></fieldDescription> </field> <field name="turmaNome" class="java.lang.String"> <fieldDescription><![CDATA[aluno.turma.nome]]></fieldDescription> </field> <field name="disciplinaNome" class="java.lang.String"> <fieldDescription><![CDATA[disciplina.nome]]></fieldDescription> </field> <field name="bimestre" class="externals.gerentes.aluno.dominio.BimestreNumero"> <fieldDescription><![CDATA[bimestre]]></fieldDescription> </field> <field name="labelProva" class="java.lang.String"> <fieldDescription><![CDATA[label]]></fieldDescription> </field> <field name="notaProva" class="java.lang.Float"> <fieldDescription><![CDATA[prova.nota]]></fieldDescription> </field> <background> <band splitType="Stretch"/> </background> <title> <band height="78" splitType="Stretch"> <staticText> <reportElement uuid="9ef73a12-0200-446d-978d-8edcddefab45" x="79" y="11" width="476" height="36"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="24" isBold="true"/> </textElement> <text><![CDATA[COLEGIO PRIORIDADE HUM]]></text> </staticText> <staticText> <reportElement uuid="110818c1-841e-4b36-a36a-4e3ca52bc84d" x="79" y="47" width="476" height="21"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="14" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Lançamento de Notas]]></text> </staticText> </band> </title> <pageHeader> <band height="65" splitType="Stretch"> <rectangle> <reportElement uuid="74c956f7-572d-45d4-ac8a-92b08ce9979d" x="0" y="0" width="393" height="48"/> </rectangle> <textField pattern="EEEEE dd MMMMM yyyy"> <reportElement uuid="69b9c68d-990a-47e7-a5fc-5dbbd01d1fc3" x="653" y="0" width="149" height="20"/> <textElement textAlignment="Right" verticalAlignment="Middle"> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> <textField> <reportElement uuid="b43c26b0-bc17-441d-a100-00ef33630ef9" x="9" y="32" width="100" height="14"/> <textElement verticalAlignment="Middle"> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA[$P{usuarioDocumento}]]></textFieldExpression> </textField> <textField> <reportElement uuid="1ac9a1f8-c27a-4115-9cca-feecb0ee41f5" x="114" y="32" width="269" height="14"/> <textElement verticalAlignment="Middle"> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA[$P{usuarioNome}]]></textFieldExpression> </textField> <staticText> <reportElement uuid="d92c533b-25f6-4d94-9998-fbe9788d0dc6" x="0" y="0" width="393" height="15"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Usuário]]></text> </staticText> <textField pattern="HH.mm"> <reportElement uuid="7805c096-4cfd-4ef5-b36a-4b8886b39605" x="702" y="20" width="100" height="20"/> <textElement textAlignment="Right"> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> <frame> <reportElement uuid="b071acd3-53d1-47c7-bbdb-27ded8d0c73d" mode="Opaque" x="1" y="16" width="391" height="15" backcolor="#E3E1E1"/> </frame> <staticText> <reportElement uuid="79e1c94d-8a89-497b-92c6-9e96c35a29a4" x="115" y="15" width="268" height="15"/> <textElement> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Nome]]></text> </staticText> <staticText> <reportElement uuid="fc90c3e7-9976-45f4-835f-cb3790a3833a" x="9" y="15" width="101" height="15"/> <textElement> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Login]]></text> </staticText> <line> <reportElement uuid="db37c73a-16d2-4a44-bdd6-38c73d83240f" x="108" y="16" width="1" height="32"/> </line> <line> <reportElement uuid="63db3eae-912a-46f8-94bb-4001e6723912" x="0" y="30" width="393" height="1"/> </line> <line> <reportElement uuid="b68bc940-a5c4-4a82-8feb-ab2bba900367" x="0" y="15" width="393" height="1"/> </line> </band> </pageHeader> <columnHeader> <band height="18" splitType="Stretch"> <frame> <reportElement uuid="446c5990-2227-4002-87bc-3e3b19121b98" mode="Opaque" x="1" y="1" width="801" height="15" backcolor="#E3E1E1"/> </frame> <staticText> <reportElement uuid="56eda211-b19f-4dba-8e19-3bcc91acae4c" x="9" y="1" width="88" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Matricula]]></text> </staticText> <staticText> <reportElement uuid="740832e5-5a65-4764-b115-d1d57d7929de" x="107" y="1" width="240" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Nome]]></text> </staticText> <staticText> <reportElement uuid="7d9f7aa2-729e-4998-99db-355491c80d90" x="613" y="1" width="53" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Bimestre]]></text> </staticText> <staticText> <reportElement uuid="ca4618a1-818f-42ca-88bd-d7c5f2a87681" x="676" y="1" width="58" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Prova]]></text> </staticText> <staticText> <reportElement uuid="7b7e9da7-37eb-469b-be77-89fdb0d69511" x="744" y="1" width="58" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Nota]]></text> </staticText> <staticText> <reportElement uuid="8dc3cbab-c941-487c-b6a5-f5a13b9f7d35" x="425" y="0" width="48" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Turma]]></text> </staticText> <staticText> <reportElement uuid="ed12cad6-5db7-4e97-9ef4-ecdda5e74f2f" x="359" y="2" width="55" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Série]]></text> </staticText> <staticText> <reportElement uuid="af93edb0-5d47-43b5-b01a-8e25a1a70e5a" x="483" y="0" width="120" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" size="11" isBold="true" isStrikeThrough="false"/> </textElement> <text><![CDATA[Disciplina]]></text> </staticText> <line> <reportElement uuid="528864d0-d46f-4a59-95ff-76b4fef49844" x="0" y="0" width="802" height="1"/> </line> <line> <reportElement uuid="61432a3f-1906-488c-8fdb-faab8333070a" x="0" y="17" width="802" height="1"/> </line> <line> <reportElement uuid="bdd57061-7fc5-4116-a5c7-97d1063f1a6b" x="96" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="da7e5266-cd76-4aa8-9bcb-d88f504ec451" x="0" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="6922726b-317b-4026-a111-806e44bc0103" x="347" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="ad9ccc2c-d01b-4a45-be2f-d276493e7114" x="413" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="c0f97a4e-b32c-480b-bc88-d9efd37befca" x="603" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="0f9446b8-107a-4fc1-97d3-0dd94dff6a4a" x="666" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="7865aa19-0bcd-43f7-baeb-aa920d682ba6" x="734" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="2f5b88b1-0e97-438a-82cd-8b9811b9d37b" x="802" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="b8254559-a202-4460-be51-62b6d45bfd06" x="472" y="0" width="1" height="16"/> </line> </band> </columnHeader> <detail> <band height="17" splitType="Stretch"> <line> <reportElement uuid="afa8d48f-843f-4069-b2ee-0fb1aa17eec1" x="1" y="16" width="802" height="1"/> </line> <textField> <reportElement uuid="41d4304f-8536-4b48-aae8-7fd0d61ad486" x="9" y="0" width="87" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{matricula}]]></textFieldExpression> </textField> <textField> <reportElement uuid="1f9282f8-bac9-4678-b84c-487df04aa04b" x="107" y="0" width="240" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{nome}]]></textFieldExpression> </textField> <textField> <reportElement uuid="94159930-15a9-43ee-b7b9-d64477fc9b33" x="359" y="0" width="54" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{serieNome}]]></textFieldExpression> </textField> <textField> <reportElement uuid="beb9ba47-80a0-40bf-9263-8a0d8a0d4b14" x="425" y="0" width="47" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{turmaNome}]]></textFieldExpression> </textField> <textField> <reportElement uuid="b03ffe55-80aa-4d25-a72c-b995dc9d7c09" x="483" y="0" width="120" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{disciplinaNome}]]></textFieldExpression> </textField> <textField> <reportElement uuid="7e798d25-76c7-4a7c-ae51-91a851fc9ef0" x="613" y="0" width="53" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[""+$F{bimestre}]]></textFieldExpression> </textField> <textField> <reportElement uuid="9187989c-ae8c-4e9b-98e6-042a7a3b5b5c" x="676" y="0" width="58" height="15"/> <textElement verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{labelProva}]]></textFieldExpression> </textField> <textField pattern="###0.00;(###0.00)"> <reportElement uuid="28f4b315-7024-4b12-9e92-e9fdd4ce16c4" x="744" y="0" width="58" height="15"/> <textElement textAlignment="Right" verticalAlignment="Middle"> <font fontName="Arial" isItalic="true"/> </textElement> <textFieldExpression><![CDATA[$F{notaProva}]]></textFieldExpression> </textField> <line> <reportElement uuid="14e97fc8-0441-4ca5-82d8-9ae2026797f9" x="96" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="2c271db8-ab32-4a8a-afc0-6ffcc12088ee" x="734" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="706baf9c-83e5-458f-a7f0-8045b4c16307" x="666" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="6d9240d2-4af2-419d-bd29-1dcd7ffc86ac" x="347" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="e137bee1-444a-4532-81f6-1d61d972dcbe" x="603" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="165b08e6-e7c5-48e9-bc36-1a23174667ec" x="472" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="d50ee816-925a-4514-875f-32001bc45070" x="413" y="1" width="1" height="16"/> </line> <line> <reportElement uuid="9d7ae678-ad9b-48f4-9435-f97799408670" x="0" y="0" width="1" height="16"/> </line> <line> <reportElement uuid="06b0cec6-6234-4462-8f22-2b4450b0a110" x="802" y="0" width="1" height="16"/> </line> </band> </detail> <columnFooter> <band height="45" splitType="Stretch"/> </columnFooter> <pageFooter> <band height="37" splitType="Stretch"> <textField> <reportElement uuid="17bcc61b-640a-423e-9ef0-c5fc36ad65dd" x="682" y="0" width="80" height="20"/> <textElement textAlignment="Right"> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA["Pagina "+$V{PAGE_NUMBER}+" de"]]></textFieldExpression> </textField> <textField evaluationTime="Report"> <reportElement uuid="08e7fa39-5919-4e06-a605-6053081f00c3" x="762" y="0" width="40" height="20"/> <textElement> <font fontName="Arial"/> </textElement> <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="42" splitType="Stretch"/> </summary> </jasperReport>

Não, amigo, a implementação la na chamada, onde vc monta o relatorio !

[code]public void gerarRelatorio() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ServletContext context = (ServletContext) externalContext.getContext();
String arquivo = context.getRealPath(“WEB-INF/relatorios/LancamentoNotas.jasper”);

    JRDataSource jrds = new JRBeanCollectionDataSource(getListaRelatorio());

    //Colocando os parametros
    Usuario usuario = recuperaUsuarioLogado();
    Map<String, Object> parametros = new HashMap<String, Object>();
    if (usuario != null) {
        parametros.put("usuarioNome", usuario.getNome());
        parametros.put("usuarioDocumento", usuario.getLogin());
    } else {
        parametros.put("usuarioNome", "");
        parametros.put("usuarioDocumento", "");
    }

    gerarRelatorioWeb(jrds, parametros, arquivo);
}

private Usuario recuperaUsuarioLogado() {
    Usuario usuarioLogado = null;
    if (SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            usuarioLogado = (Usuario) principal;
        }
    }
    return usuarioLogado;
}

private void gerarRelatorioWeb(JRDataSource jrds, Map<String, Object> parametros, String arquivo) {
    ServletOutputStream servletOutputStream = null;
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

    try {
        servletOutputStream = response.getOutputStream();
        JasperRunManager.runReportToPdfStream(new FileInputStream(new File(arquivo)), servletOutputStream, parametros, jrds);
        response.setContentType("application/pdf");
        servletOutputStream.flush();
        servletOutputStream.close();
        context.renderResponse();
        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}[/code]

Amigo, ao meu ver sua implementação está ok. Irei colocar a minha em baixo, para comparação:

É interessante você ver também, a questão do local onde seu relatorio esta. Veja onde coloco o meu, pelo fato de ser uma aplicação WEB, todos os seus recursos deveram estar dentro do WebContent.

protected void gerarRelatorio(String localRelatorio, Map&lt;String, Object&gt; parametros , Collection&lt;T&gt; lista) throws MalformedURLException{
		
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        ServletContext contextS = (ServletContext) externalContext.getContext();
		
		ServletOutputStream servletOutputStream = null;
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        String arquivo = contextS.getRealPath("/WEB-INF/classes/br/com/sistema/relatorios/" + localRelatorio);
		
		try {
			
			servletOutputStream = response.getOutputStream();
			
		    JasperRunManager.runReportToPdfStream(new FileInputStream(new File(arquivo)), response.getOutputStream(), parametros, new JRBeanCollectionDataSource(lista));
			
		    response.setContentType("application/pdf");
            servletOutputStream.flush();
            servletOutputStream.close();
            context.renderResponse();
            context.responseComplete();
		    
		} catch (JRException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

Está igual…

Meu relatório está ficando em WEB-INF/relatorios.

Vc tb está hospedado na integrator?

Estava vendo pela internet e alguns lugares estava falando sobre fonts que não estão instalado no servidor.

Eu vi uma solução que colocava um jar com as fonts do relatório. Fiz isso e fiquei na mesma…tá difícil…

Cara, tenho varios sistemas na Integrator, mas tipo, esse pro da fonte eu realmente tive e dei a dica a alguns dias atras pra outra pessoa daqui do GUJ.

O que aconteceu é que eu estava utilizando uma fonte que a JDK do integrator não possuia. Ja quando hospedei no Jelastic funcionava. Ai so fiz colocar a fonte original do Jasper ai funcionou.

Qual foi a fonte, lembra?

Não sei se é isso, mas vale apena tentar.

O erro que dava era esse mesmo?

Era a Calibri. Daí mudei para a default Sans serif, e funcionou. Faça o teste. Crie outro jasper só para ver qual fonte vem setada por default, daí pegue ela e coloque no seu relatorio.

Olha que bizarro…

Criei um relatório em branco e fiz o teste com ele.
O erro continua dando:

[b]This page contains the following errors:

error on line 1 at column 1: Document is empty
error on line 1 at column 1: Encoding error

Below is a rendering of the page up to the first error.
[/b]

Logo, posso tirar qualquer problema de font. O pior mesmo é que não dá nenhum erro no Glassfish, só esse erro na página.

amigo, tente colocar conteudo para ser apresentado nesse primeiro. Qual a fonte q vc está utilizando no outro?

To com o mesmo problema no integrator e usando a fonte padrão SansSerif … alguém tem alguma solução?