Subreport is not printed

Asked

Viewed 107 times

3

I have a report and I need to use subreports, I can generate the report, but the subreports are being printed blank, as if they had no data

XML of the Report

<?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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="20345f4c-6c2a-42bd-9b2e-f2102198a3c2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="407"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["/home/juliana/NetBeansProjects/SistemaWeb/SistemaWeb-war/web/relatorios/meuRelatorio/"]]></defaultValueExpression>
</parameter>
<field name="idLivroOrdem" class="java.lang.Long"/>
<field name="dataCriacao" class="java.util.Date"/>
<field name="dataRealInicioObraServico" class="java.util.Date"/>
<field name="art.numeroArt" class="java.lang.String"/>
<field name="art.nomeProfissionalContratado" class="java.lang.String"/>
<field name="art.rnpProfissionalContratado" class="java.lang.String"/>
<field name="art.titulosProfissionalContratado" class="java.lang.String"/>
<field name="art.registroRegionalProfissionalContratado" class="java.lang.String"/>
<field name="art.enderecoObraServico.tipoLogradouro" class="java.lang.String"/>
<field name="art.enderecoObraServico.logradouro" class="java.lang.String"/>
<field name="art.enderecoObraServico.numero" class="java.lang.String"/>
<field name="art.enderecoObraServico.bairro" class="java.lang.String"/>
<field name="art.enderecoObraServico.cidade" class="java.lang.String"/>
<field name="art.enderecoObraServico.uf" class="java.lang.String"/>
<field name="art.enderecoObraServico.cep" class="java.lang.String"/>
<field name="art.nomeProprietario" class="java.lang.String"/>
<field name="art.cpfCnpjProprietario" class="java.lang.String"/>
<field name="art.atividadesArtAntigas" class="java.util.List"/>
<field name="relatos" class="java.util.List"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="88" splitType="Stretch">
        <image>
            <reportElement uuid="b9926800-5924-43ce-b890-0c69175b4be2" x="17" y="24" width="58" height="50"/>
            <imageExpression><![CDATA["/home/juliana/NetBeansProjects/SistemaWeb/SistemaWeb-war/web/relatorios/brasaoReport.png"]]></imageExpression>
        </image>
        <staticText>
            <reportElement uuid="c984a13e-1766-4d56-9810-32a4ce516b9c" x="18" y="74" width="57" height="14"/>
            <textElement>
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[RELATORIO]]></text>
        </staticText>
        <textField pattern="dd/MM/yyyy">
            <reportElement uuid="b52bd63b-2318-4e33-ad46-80742e42ce7c" x="18" y="3" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
        </textField>
        <textField pattern="HH:mm">
            <reportElement uuid="d340f061-db24-4dc2-9dae-bd865c759e0c" x="497" y="4" width="58" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement uuid="658063ed-4935-4091-98ee-960dd560b63b" x="169" y="67" width="219" height="20"/>
            <textElement/>
            <text><![CDATA[Resolução CONFEA N. 1094 de 31/10/2017]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="5d4c0c9e-2c99-4a05-bfb5-d58412055fc7" x="397" y="34" width="51" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[Livro Nº]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="c96c6f9e-f852-4790-b4c6-0ff5a9e85f84" x="401" y="62" width="27" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[ART]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="0de103ba-c090-4bde-ba42-296ca8b15b61" x="213" y="34" width="122" height="28"/>
            <textElement>
                <font size="14" isBold="true"/>
            </textElement>
            <text><![CDATA[Livro de Ordem]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
            <reportElement uuid="66b6d0aa-1f5e-44d3-b495-d7566a790013" x="448" y="34" width="107" height="20" isPrintWhenDetailOverflows="true"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{idLivroOrdem}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement uuid="7e72d780-1d5f-44ff-a154-2b7fa71a65cb" stretchType="RelativeToTallestObject" x="428" y="62" width="127" height="20" isPrintWhenDetailOverflows="true"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.numeroArt}]]></textFieldExpression>
        </textField>
    </band>
</title>
<detail>
    <band height="345" splitType="Stretch">
        <rectangle>
            <reportElement uuid="73c0382e-3edd-4a6f-8402-73ff04fb8cf8" mode="Transparent" x="10" y="10" width="525" height="111"/>
            <graphicElement>
                <pen lineStyle="Dotted"/>
            </graphicElement>
        </rectangle>
        <staticText>
            <reportElement uuid="1b994936-15dd-4b52-acad-8aa96655daec" x="25" y="21" width="167" height="20"/>
            <textElement>
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[RESPONSÁVEL TÉCNICO]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="308c5741-335b-4490-938c-d36c4bc4f8d9" x="25" y="88" width="132" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[Título Profissional: ]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="37d92aa9-f250-4976-ba30-0c736d57452d" x="345" y="49" width="42" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[RNP: ]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="f38fd7f3-9b95-40ef-93c0-3a74e666cfed" x="372" y="88" width="56" height="20"/>
            <textElement>
                <font isBold="true"/>
            </textElement>
            <text><![CDATA[Registro: ]]></text>
        </staticText>
        <rectangle>
            <reportElement uuid="041e531d-506e-44f3-9482-065e299b4284" mode="Transparent" x="10" y="131" width="525" height="204"/>
            <graphicElement>
                <pen lineStyle="Dotted"/>
            </graphicElement>
        </rectangle>
        <staticText>
            <reportElement uuid="c2984258-b211-48ff-888d-912bf2af44f0" x="20" y="144" width="190" height="20"/>
            <textElement>
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[DADOS DA OBRA/SERVIÇO]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="5c34c7f2-f5cf-4ba9-8481-fdee3737f054" x="20" y="237" width="85" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[Proprietário: ]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="ea60b9d7-59da-43c8-b9f5-54399418799e" x="299" y="237" width="69" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[CPF/CNPJ: ]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="08e1c840-2ba1-4b80-9a38-e83f94970dca" x="20" y="300" width="242" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[Data Real de Início da Obra/Serviço:]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="956a35d2-d3d3-4e48-8aec-c064de3fc3c2" x="20" y="269" width="172" height="20"/>
            <textElement>
                <font size="11" isBold="true"/>
            </textElement>
            <text><![CDATA[Data de Abertura do Livro: ]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
            <reportElement uuid="8c095ac4-50e4-4c65-8a4d-dc2dde2e8d9f" x="25" y="49" width="310" height="20" isPrintWhenDetailOverflows="true"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.nomeProfissionalContratado}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="f197c9ff-6a88-46cf-bb4a-ec6f554fc609" x="387" y="49" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.rnpProfissionalContratado}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="35d833ae-4e76-46e0-a7fc-3e4b758d5593" x="428" y="88" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.registroRegionalProfissionalContratado}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="6acae8c1-c3d7-43d9-bcde-98b16fdd8b2c" x="157" y="88" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.titulosProfissionalContratado}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="2f4cc7ae-63fb-480f-9e4c-958add716f24" x="24" y="171" width="101" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.tipoLogradouro}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="ffc14974-a57e-4ec3-b550-6864e0a00737" x="446" y="171" width="82" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.numero}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="2ab24562-4de4-4c60-9658-0425ea3f0b1d" x="25" y="195" width="188" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.bairro}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="97b13707-c732-4e24-ae5c-a72b04ce14af" x="220" y="195" width="148" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.cidade}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="ff625d8e-02ca-450f-82bb-c772495f683c" x="373" y="195" width="41" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.uf}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="ca219071-ef0d-46bc-807e-50578559dca3" x="428" y="195" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.cep}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="952b3171-59b5-4041-b03e-1cf8b2517be5" x="105" y="237" width="189" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.nomeProprietario}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="59ebd520-b78d-4c2f-8a75-8f77469c46d4" x="373" y="237" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.cpfCnpjProprietario}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="deee2765-35ff-4f06-9e9c-0ab01ac5a0bf" x="199" y="269" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{dataCriacao}]]></textFieldExpression>
        </textField>
        <textField pattern="dd/MM/yyyy">
            <reportElement uuid="36b94535-b3f3-4742-9a0f-4631ad60ea53" x="262" y="300" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{dataRealInicioObraServico}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="a83796be-169e-45b9-878f-d693add9d3ab" stretchType="RelativeToTallestObject" x="131" y="171" width="297" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{art.enderecoObraServico.logradouro}]]></textFieldExpression>
        </textField>
    </band>
    <band height="126">
        <staticText>
            <reportElement uuid="f0d1de0c-2f50-44d8-a3a2-81e97ac36829" x="20" y="26" width="137" height="20"/>
            <textElement>
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[ATIVIDADE TÉCNICA]]></text>
        </staticText>
        <rectangle>
            <reportElement uuid="c2a07437-cfa5-45a7-a000-7b7bf95d8482" mode="Transparent" x="10" y="15" width="525" height="95"/>
            <graphicElement>
                <pen lineStyle="Dotted"/>
            </graphicElement>
        </rectangle>
    </band>
    <band height="257">
        <staticText>
            <reportElement uuid="5d941d6e-2157-41f6-96d9-f3ebb0df4745" x="9" y="8" width="100" height="20"/>
            <textElement>
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[RELATOS]]></text>
        </staticText>
        <subreport>
            <reportElement uuid="7ff6cc78-e7d5-463d-8803-d4f31edef562" x="10" y="38" width="524" height="208"/>
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{relatos})]]></dataSourceExpression>
            <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "relatos.jasper"]]></subreportExpression>
        </subreport>
    </band>
</detail>
<summary>
    <band height="42" splitType="Stretch">
        <textField>
            <reportElement uuid="4a2c60f0-dfad-425e-b0b2-0acad3c6cd54" x="214" y="14" width="80" height="20"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
        </textField>
        <textField evaluationTime="Report">
            <reportElement uuid="aa17bcf8-b782-4986-8fde-17b96803f1d8" x="294" y="14" width="40" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
    </band>
</summary>

Printing Method

public static void imprimirLivroOrdem(LivroOrdem livroOrdem) throws Exception {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

    String caminho = "/relatorios/";
    String subPasta = caminho + "livroOrdem/";
    String relatorio = subPasta + "livroOrdem.jasper";

    List<LivroOrdem> livrosOrdem = new ArrayList<LivroOrdem>();
    livrosOrdem.add(livroOrdem);

    InputStream reportStream = context.getExternalContext().getResourceAsStream(relatorio);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("SUBREPORT_DIR", context.getExternalContext().getRealPath(subPasta) + File.separator);
    map.put("BRASAO_DIR", context.getExternalContext().getRealPath(caminho) + File.separator);

    response.setContentType("application/pdf");
    response.setHeader("Content-disposition", "attachment;filename=livroOrdem.pdf");
    //response.setHeader("Content-disposition", "inline;filename=livroOrdem.pdf");

    try {
        ServletOutputStream servletOutputStream = response.getOutputStream();
        JRBeanCollectionDataSource fonteDados = new JRBeanCollectionDataSource(livrosOrdem);

        JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, map, fonteDados);
        servletOutputStream.flush();
        servletOutputStream.close();
    } 

    catch (JRException e) {
        System.out.println(e.getMessage());
    } 

    catch (IOException e) {
        System.out.println(e.getMessage());
    } 

    finally {
        context.responseComplete();
    }
}
  • If possible post also the code of one of the reports being printed blank.

  • Another question, Reports are being printed blank without any label or content, or they have static content but not the values you passed on?

  • Can you reduce the report just to call the subreport? It has many lines to say. Something tells me the trouble is that the subreport is not going the right way

  • The way I handled subreports can be seen in this question: https://answall.com/q/291236/64969

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.