Jasper报告:仅在第一条记录

时间:2016-09-26 14:33:16

标签: jasper-reports subreport

我的主报告中有一个子报告。这是详细的乐队。 问题是它只运行主报告的第一条记录。我希望它可以运行所有细节带的记录。它没有显示在其他页面上。 为了运行它,我传输1个sql查询参数来提供详细信息带。

在第一条记录的页面中,显示如下图所示: enter image description here

在后续记录的页面中,它不显示或不返回数据(我不能说)。 如下图所示: enter image description here

这是主要报告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>

子报告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 个答案:

答案 0 :(得分:0)

您的报告存在以下几个问题:

  1. 子报表的末尾和细节带的末尾之间留有太多空间。 JasperReports将尝试保留该空白,并且可能导致不必要的带/页溢出,甚至在某些情况下无限循环运行。
  2. 当查询没有返回任何内容时,您的子报表可能不会产生任何结果(详细信息带的重复次数与mainDataset中的记录数相同 - 由queryString生成的记录数)。这可能就是你在textField之后什么也看不见的原因。要对此进行测试,请手动检查SQL查询,或者在子报表中设置:
  3.   

    无数据类型:无数据部分

    并使用您选择的noData添加staticText个频段(来自Jaspersoft Studio的“大纲”视图)。当子报表的mainDataset为空时,这将仅触发noData波段的渲染。这样,当没有任何东西可以显示时,你可以拥有某种占位符。