0
votes

I have a subreport in my main report. This is in the detail band. The problem is it only runs for the first record of the main report. I wish it run for all records of detail band. It is not showing on another pages. To run it, I transfer 1 sql query parameter that feeds the detail band.

In the pages of the first record, it appears, as shown in the image below: enter image description here

In the pages of the subsequent records, it does not showing or does not return data (I can not say). As the image below: enter image description here

This is the main report jrxml:


        <?xml version="1.0" encoding="UTF-8"?>
        <!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
        <!-- 2016-09-26T11:09:48 -->
        <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd&quot; name="1350" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="511" leftMargin="42" rightMargin="42" topMargin="71" bottomMargin="71" uuid="55ddfd1b-0389-4716-a115-0b6966f4bd05">
        <property name="net.sf.jasperreports.export.xml.start.page.index" value="1"/>
        <property name="net.sf.jasperreports.export.xml.end.page.index" value="2"/>
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.unit." value="pixel"/>
        <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.topMargin" value="cm"/>
        <property name="com.jaspersoft.studio.unit.bottomMargin" value="cm"/>
        <property name="com.jaspersoft.studio.unit.leftMargin" value="cm"/>
        <property name="com.jaspersoft.studio.unit.rightMargin" value="cm"/>
        <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="SQLSRV_SQLDEV"/>
        <parameter name="CodCand" class="java.lang.Integer" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
        </parameter>
        <parameter name="PAGE_INDEX" class="java.lang.Integer" isForPrompting="false">
        <defaultValueExpression><![CDATA1]></defaultValueExpression>
        </parameter>
        <queryString>
        <![CDATA[ /* QUERY */ ]]>
        </queryString>
        <field name="Cod_cand" class="java.lang.Integer"/>
        <field name="EstadoReg_cand" class="java.lang.Integer"/>
        <field name="Nome_cand" class="java.lang.String"/>
        <field name="Sigla_idiomaNav" class="java.lang.String"/>
        <pageHeader>
        <band height="70" splitType="Stretch">
        <image>
        <reportElement x="0" y="0" width="110" height="50" uuid="db7d5ce0-2740-4b4a-b84e-d4aacac33ced"/>
        <imageExpression><![CDATA["/home/diego.queres/Desenv/Relatórios Clientes/MyReports/Cafe com leite.JPG"]]></imageExpression>
        </image>
        </band>
        </pageHeader>
        <detail>
        <band height="563" splitType="Stretch">
        <textField>
        <reportElement x="0" y="10" width="260" height="30" uuid="ff0bc8d6-87d0-4fba-84fe-b3def51ac8f1"/>
        <textElement>
        <font fontName="Arial" size="18"/>
        </textElement>
        <textFieldExpression><![CDATA[$F{Nome_cand}]]></textFieldExpression>
        </textField>
        <textField>
        <reportElement positionType="Float" x="100" y="60" width="160" height="30" uuid="dd77bdb7-560b-4054-88ea-2b14f5032b06"/>
        <textFieldExpression><![CDATA[$F{Sigla_idiomaNav}]]></textFieldExpression>
        </textField>
        <staticText>
        <reportElement positionType="Float" x="0" y="60" width="100" height="30" uuid="2a0e78b4-1fc0-428d-95fa-86c7f8e669a0"/>
        <text><![CDATA[Idioma candidato]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
        <reportElement positionType="Float" x="100" y="90" width="410" height="40" uuid="54e06bcd-be90-48ca-b861-78b39f55681c"/>
        <textFieldExpression><![CDATA[$F{EstadoReg_cand} + "\n" +
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pretium quam non odio cursus viverra. Integer dolor sapien, suscipit quis placerat eget, tincidunt at ipsum. Morbi molestie sit amet tellus non commodo. Donec vel arcu lobortis, bibendum metus vitae, varius leo. Maecenas ultrices nisi id sapien volutpat viverra. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed eget erat non felis tempus sodales in id quam. Proin suscipit porta faucibus. Etiam vitae elit facilisis, pulvinar ipsum at, facilisis ante. Nulla ac mauris erat. Curabitur sit amet metus id metus cursus lacinia eget ut orci. Nullam ornare erat nulla, pretium viverra justo hendrerit ac. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent sed nisl risus. Nulla facilisi." +
        "\n" +
        "Curabitur sodales finibus arcu at condimentum. Integer at tempor mi, eu euismod dolor. Nulla facilisi. Suspendisse potenti. Nullam feugiat turpis condimentum turpis tempor sagittis. Pellentesque accumsan elementum auctor. Mauris orci dui, convallis id sagittis a, dapibus eget dui. Vivamus sit amet ante id elit malesuada porta non eget dui. Nulla nisi sem, dictum at metus eu, facilisis ornare neque. Pellentesque in lectus vel libero laoreet faucibus vel non odio. Aenean euismod neque eu nisl rutrum fringilla. In nibh enim, sollicitudin ut aliquet sit amet, pulvinar sit amet odio. Duis fringilla, odio eget fermentum eleifend, urna sem volutpat diam, at dictum elit turpis ut mauris. Vivamus rutrum turpis ut ex sodales vulputate." +
        "\n" +
        "Curabitur laoreet ligula et augue tincidunt pharetra. Fusce finibus non tellus in sollicitudin. Aliquam quis venenatis tellus. Quisque leo erat, rutrum nec ex a, dictum interdum augue. In et tincidunt diam. Sed sagittis nibh id ex laoreet hendrerit. Aliquam non nunc odio. Nam dolor diam, eleifend sit amet enim vel, laoreet tincidunt nibh. Etiam vitae elementum mi. Ut ornare a sapien sit amet congue." +
        "\n" +
        "Maecenas tempor cursus mauris. Mauris vehicula pharetra scelerisque. Maecenas feugiat justo purus, vel fermentum odio venenatis eu. Aliquam quis libero maximus, convallis odio a, eleifend nisi. Phasellus placerat, nulla ut rutrum sagittis, magna turpis tincidunt nisl, vel mollis libero massa ut arcu. Donec et tincidunt sem, ut pellentesque arcu. Sed laoreet ornare gravida. Nunc mauris mauris, elementum sit amet porttitor vel, feugiat ut sem. Donec ultrices quam mollis blandit facilisis. Morbi mollis semper enim, nec lobortis nisl blandit at. Ut leo magna, maximus ullamcorper finibus et, bibendum ut eros." +
        "\n" +
        "Nam eros risus, lacinia semper augue sed, interdum dapibus turpis. Mauris placerat iaculis fringilla. Vestibulum ullamcorper nibh et tortor ullamcorper accumsan. In ipsum eros, consectetur non blandit non, eleifend id elit. Suspendisse non bibendum mi. Suspendisse finibus eleifend mauris. Integer rutrum, ex vitae suscipit luctus, sapien erat tincidunt dui, sit amet ultricies magna sem at ligula. Fusce dictum, dolor sed commodo rutrum, eros quam eleifend libero, nec aliquam libero risus vitae ipsum. Vivamus nec libero metus. Mauris volutpat sapien vitae tortor tincidunt semper. Integer aliquet purus a urna dictum, id vehicula ante convallis. Suspendisse dolor velit, volutpat ut mi non, faucibus lobortis nulla. Quisque sed nisi nunc."]]></textFieldExpression>
        </textField>
        <staticText>
        <reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="90" width="100" height="40" uuid="2452709f-be5e-4c5a-bece-c54a03e532f7"/>
        <text><![CDATA[EstadoReg_cand]]></text>
        </staticText>
        <break>
        <reportElement x="0" y="550" width="509" height="1" uuid="cfd93607-c001-4860-8fe5-848979c466ce"/>
        </break>
        <subreport>
        <reportElement positionType="Float" x="100" y="130" width="409" height="70" uuid="e3dea3c0-56e8-42c8-b35c-d74b42d79858"/>
        <subreportParameter name="CodCand">
        <subreportParameterExpression><![CDATA[$F{Cod_cand}]]></subreportParameterExpression>
        </subreportParameter>
        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
        <subreportExpression><![CDATA["/home/diego.queres/Desenv/Relatórios Clientes/MyReports/1350-formacoes.jasper"]]></subreportExpression>
        </subreport>
        </band>
        </detail>
        <pageFooter>
        <band height="66" splitType="Stretch">
        <textField>
        <reportElement x="409" y="36" width="100" height="30" uuid="422e0e4d-35f2-42eb-bfe1-c805991fd470"/>
        <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
        </textField>
        </band>
        </pageFooter>
        </jasperReport>

Subreport jrxml:


<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
<!-- 2016-09-27T10:20:16 -->
<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="1350-formacoes" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a9eac827-ef0f-401c-80eb-8cf6417e4906">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="SQLSRV_SQLDEV"/>
    <parameter name="CodCand" class="java.lang.String"/>
    <queryString>
        <![CDATA[select * from [dbo].[candform] where codcand =  $P{CodCand} ]]>
    </queryString>
    <field name="CodCand_form" class="java.lang.Integer"/>
    <field name="Descr_form" class="java.lang.String"/>
    <field name="Instit_form" class="java.lang.String"/>
    <field name="Pais_form" class="java.lang.String"/>
    <field name="Estado_form" class="java.lang.String"/>
    <field name="TipoCurso_form" class="java.lang.String"/>
    <field name="Descr_cursoGrad" class="java.lang.String"/>
    <field name="Descr_cursoPGrad" class="java.lang.String"/>
    <field name="Duracao_form" class="java.lang.String"/>
    <field name="dataStatus_form2" class="java.lang.String"/>
    <field name="dataStatus_form3" class="java.lang.String"/>
    <field name="dataStatus_form" class="java.sql.Timestamp"/>
    <field name="Situacao_form" class="java.lang.String"/>
    <field name="cod_form" class="java.lang.Integer"/>
    <field name="cod_formresumido" class="java.lang.Integer"/>
    <field name="Nivel" class="java.lang.String"/>
    <field name="Area_form" class="java.lang.String"/>
    <field name="RowNumber_form" class="java.lang.Integer"/>
    <field name="RowNumber_codform" class="java.lang.Integer"/>
    <detail>
        <band height="70">
            <textField>
                <reportElement x="120" y="10" width="450" height="30" uuid="41091178-6353-4264-81ff-07919aaeb4dd"/>
                <textFieldExpression><![CDATA[$F{Descr_form}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="20" y="10" width="100" height="30" uuid="73c9de13-3e0b-4c65-a9b3-628f419c8efc"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Descr_form]]></text>
            </staticText>
            <textField>
                <reportElement x="120" y="40" width="450" height="30" uuid="ec4daab6-894e-4d8c-9823-a33d5acafa38"/>
                <textFieldExpression><![CDATA[$F{Instit_form}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="20" y="40" width="100" height="30" uuid="5408a543-a168-437d-89ef-1ab6671a1b38"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Instit_form]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

1
In which band your subreport placed?sanluck
Looks fine to me. Are you sure $F{Cod_cand} is being filled correctly?tobi6
Please also post the JRXML of the subreport.Narcis
Subreport is placed on Detail banddiegoqueres
$F{Cod_cand} is filled in detail band, to each record.diegoqueres

1 Answers

0
votes

There are a couple of issues with your report:

  1. There is too much space left between the end of the subreport and the end of the detail band. JasperReports will try to preserve that whitespace and it may cause unnecessary band/page overflow and even run in an infinite loop in some cases.
  2. Your subreport may produce no results when the query returns nothing(the detail band is repeated as many times as the number of records you have in the mainDataset - the one produced by the queryString). This is probably the reason you see nothing after that textField. To test this, either manually check your SQL query or, in the subreport, set:

When No Data Type: No Data Section

and add a noData band (from the Outline view in Jaspersoft Studio) with a staticText of your choice. This will trigger the rendering of only the noData band when the mainDataset of your subreport is empty. This way you can have some sort of place holder when there is nothing to display.