I made a jasper file and it shows a new page, there will be a blank page, please tell me how to fix it.
I use iReport-5.6.0 to modify it.
Main (part of the sub report)
<band height="109" splitType="Immediate">
<subreport>
<reportElement style="style_detail" positionType="Float" x="0" y="31" width="445" height="23" uuid="8d1ddd6f-a366-4634-bc00-eea444fa9920"/>
<subreportParameter name="ENDTEXT1">
<subreportParameterExpression><![CDATA[$P{ENDTEXT1}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{letterTransList4})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
Sub 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="correspondenceReportPOABG_subreport1" pageWidth="444" pageHeight="802" whenNoDataType="AllSectionsNoDetail" columnWidth="444" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="7e2bd990-3814-4075-a5f2-e4d4a29b5bad">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.export.docx.flexible.row.height" value="true"/>
<style name="style_header" hAlign="Left" vAlign="Top" fontName="" fontSize="15"/>
<style name="style_detail" hAlign="Left" vAlign="Top" fontName="" fontSize="14" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false">
<paragraph lineSpacing="Single"/>
</style>
<parameter name="ENDTEXT1" class="java.lang.String"/>
<field name="detail" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="1" splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="21" splitType="Immediate">
<textField isStretchWithOverflow="true">
<reportElement style="style_detail" positionType="Float" x="0" y="0" width="444" height="21" uuid="186ec40e-42e2-488a-a21c-a5bba58c0e90"/>
<textElement markup="none">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{detail}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Immediate"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
I made a jasper file and it shows a new page, there will be a blank page, please tell me how to fix it.
I want no blank pages. How should I set it up?
I use iReport-5.6.0 to modify it.
The page format on your subreport is currently set to pageHeight="802" which equals one full A4 page and that's why it's using a full page in your main report.
I'd recommend adjusting the page format of the subreport to match the allocated space in the main report.
Related
I'd like to create a simple Jasper Report, with subreport, but I cannot make it work.
For example, I have two, simple report.
test1.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:29:14 -->
<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="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="553ce57f-5ea7-48e5-8eaa-dcfecf31880a">
<queryString>
<![CDATA[select dummy from dual]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="89" y="0" width="100" height="30" uuid="04f9b63d-265b-45f0-a249-41464df6b4c0"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="227" y="0" width="100" height="30" uuid="0c7db454-653c-4dcf-af94-a0f1c9962b91"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="352" y="0" width="100" height="30" uuid="7ad861d5-74ba-49e9-95c7-4cd01d184dbe"/>
<text><![CDATA[x]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="257" splitType="Stretch">
<textField>
<reportElement x="89" y="66" width="100" height="30" uuid="4099071d-8bfc-4e61-a697-af078ccb626a"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="227" y="68" width="100" height="30" uuid="a955ca4e-aecd-48c3-8b7c-face6295b879"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="352" y="65" width="100" height="30" uuid="5a998443-ae4f-457d-a565-67b4f3405951"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["test4.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
test4.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:27:56 -->
<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="test4" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c55e71d8-6eb9-4f20-9263-c50c295fa0d1">
<parameter name="a" class="java.lang.String"/>
<queryString>
<![CDATA[select dummy from dual where 1=1]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="364" y="0" width="100" height="30" uuid="1d48df0f-3f4c-489f-b479-e981b2727590"/>
<text><![CDATA[b]]></text>
</staticText>
<staticText>
<reportElement x="478" y="0" width="100" height="30" uuid="397b1c60-fe4d-4f41-a7a4-7c585a57ac15"/>
<text><![CDATA[a]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<staticText>
<reportElement x="239" y="58" width="100" height="30" uuid="5b5c86c0-1b1b-44d3-87cb-2ad2782a3408"/>
<text><![CDATA[test4]]></text>
</staticText>
<textField>
<reportElement x="364" y="66" width="100" height="30" uuid="d3217648-88a1-4d88-b2b0-7f7cc4e598c6"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="478" y="47" width="100" height="30" uuid="f2c6bfb9-ee73-4928-8ce4-0a83060d0801"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The selects provide one result (the DB is Oracle), but the subreport isn't visible in the repport made from test1.jrxml. But a whole new, empty page is at the end of the report.
Can you show me what's wrong with this example? I'd tried a lot's of stuff (default value in the subreport, When No Data = All Sections, No Detail setting in the subReport's header, and a lot of stuff, I can't remember), but nothing helped.
In your example I can see two problems:
You need to pass absolute path to subreport (this is normally done by parameter, so that it can be controlled on runtime)
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
</parameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
You need to pass the report connection to the subreport
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
</subreport>
I try to use subreport using JasperSoft Studio but I get the exception below. It cannot find the subreport file although it is there.
net.sf.jasperreports.engine.JRException:Resource not found at: D:\\JASPERREPORTS\\MyReports
Below is the configuration of main report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a6d6643-1d79-4e5e-b39d-a773bba37c12">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="kai3_adapter"/>
<queryString>
<![CDATA[select * from cm_crew]]>
</queryString>
<field name="OID" class="java.math.BigDecimal"/>
<field name="CREW_OID" class="java.lang.String"/>
<field name="CONTACT_OID" class="java.math.BigDecimal"/>
<field name="ACTIVE" class="java.lang.String"/>
<field name="ONSHIFT" class="java.lang.String"/>
<field name="SHIFT_ID" class="java.lang.String"/>
<field name="SHIFT_START" class="java.sql.Timestamp"/>
<field name="CREW_STATUS" class="java.lang.String"/>
<group name="CREW_OID">
<groupExpression><![CDATA[$F{CREW_OID}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="141" height="20" uuid="fc7cf2eb-2922-42e3-b446-fa1cba3239d6"/>
<text><![CDATA[CREW_OID]]></text>
</staticText>
<staticText>
<reportElement x="141" y="0" width="138" height="20" uuid="1fb08aed-592e-437d-9c3c-87e763dc81f8"/>
<text><![CDATA[ACTIVE]]></text>
</staticText>
<staticText>
<reportElement x="279" y="0" width="138" height="20" uuid="76eaa47f-6f18-4210-a607-a6456b1cc4ed"/>
<text><![CDATA[ONSHIFT]]></text>
</staticText>
<staticText>
<reportElement x="417" y="0" width="138" height="20" uuid="273fca2c-2b50-4157-ab3b-8545d94855f3"/>
<text><![CDATA[CREW_STATUS]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="257" splitType="Stretch">
<textField>
<reportElement x="0" y="13" width="141" height="20" uuid="ef3acaa1-b11a-4b3d-b90d-7da18fc15dfa"/>
<textFieldExpression><![CDATA[$F{CREW_OID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="141" y="13" width="138" height="20" uuid="2c29e96a-d712-4aff-9449-46f523ebbad8"/>
<textFieldExpression><![CDATA[$F{ACTIVE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="279" y="13" width="81" height="20" uuid="70df46c9-e63a-45a0-8c6e-82e38c260681"/>
<textFieldExpression><![CDATA[$F{ONSHIFT}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="380" y="20" width="165" height="170" uuid="3c312fc6-a389-4e46-af09-ddb1bfaa353f"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["D:\\JASPERREPORTS\\MyReports\\"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Following Sharad's answer, if it still doesn't generate the file (which happened to me), you can try this:
Before previewing the report, you can try to compile it first. If you open your jrxml file (the one that includes the subreport), you may notice a little icon (a little file with some binary string) on the upper bar of your editor. Clicking this button should generate the file you're expecting.
I created a new answer because I wanted to add an image showing the button:
Notice that this may also work: clean the projects that contain the reports using "Project > Clean...". And then right click your project in the "Project Explorer" (usually on your left), and then click "Build Project".
Send the "SUBREPORT_DIR" parameter from the application that calls the report.
For example, in Java:
params.put("SUBREPORT_DIR", "reports/folder/");
Just point to the directory, not the file.
If you use Maven, set Maven resource tags properly in pom.xml
Try to give the subreport name in the subreport path like this :-
"D:\\JASPERREPORTS\\MyReports\\subreport.jasper"
Even .jasper file is not there just give the subreport.jasper it will automatically compile the subreport.jrxml file and generate the .jasper file.
I'm having a problem with subreport connected to a XML file. When I execute the report the preview don't show the subreport data, but if I execute the subreport alone, it shows the data correctly. What am I doing wrong?
Data File:
<REPORTDATA>
<HEAD>
<NUMBER>1</NUMBER>
<DESC>BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</HEAD>
<GRID1>
<line id="1">
<NUMBER>11</NUMBER>
<DESC>g11BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
<line id="2">
<NUMBER>12</NUMBER>
<DESC>g12BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
</GRID1>
<GRID2>
<line id="1">
<NUMBER>21</NUMBER>
<DESC>g21BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
<line id="2">
<NUMBER>22</NUMBER>
<DESC>g22BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
</GRID2>
Report:
<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="reporttest" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6a9eed56-d1c3-46d8-9e16-4166c146b8a3">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\A2O\\Desktop\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[/REPORTDATA/HEAD]]>
</queryString>
<field name="NUMBER" class="java.lang.String">
<fieldDescription><![CDATA[NUMBER]]></fieldDescription>
</field>
<field name="DESC" class="java.lang.String">
<fieldDescription><![CDATA[DESC]]></fieldDescription>
</field>
<field name="DATE" class="java.lang.String">
<fieldDescription><![CDATA[DATE]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement uuid="bd7929b3-092d-44b9-b488-c0418fb57749" x="4" y="6" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="de902808-67e8-4b08-bd0b-c1d735409843" x="6" y="32" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="86d57bd0-01d3-4b1f-b9bb-0eb7cf2c19fc" x="5" y="56" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="13" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="12" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="26" splitType="Stretch">
<staticText>
<reportElement uuid="819f4027-8ad0-46b4-b07c-c80234fe8411" x="12" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Static text]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="11" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="9" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch">
<subreport>
<reportElement uuid="4ab29d23-9ead-491e-8ca3-8f9790280026" x="0" y="0" width="555" height="42"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "reporttest_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</summary>
Subreport:
<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="reporttest_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ca109af7-4e08-405d-b43f-4062115c500e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[/REPORTDATA/GRID1/line]]>
</queryString>
<field name="NUMBER" class="java.lang.String">
<fieldDescription><![CDATA[NUMBER]]></fieldDescription>
</field>
<field name="DESC" class="java.lang.String">
<fieldDescription><![CDATA[DESC]]></fieldDescription>
</field>
<field name="DATE" class="java.lang.String">
<fieldDescription><![CDATA[DATE]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band height="36" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="69" splitType="Stretch">
<staticText>
<reportElement uuid="867a24dd-6172-40ef-be33-f8e51fa21207" x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Grid1 data:]]></text>
</staticText>
<staticText>
<reportElement uuid="0885dada-a149-4cb7-b82c-fdfa9847061d" x="32" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[NUMBER]]></text>
</staticText>
<staticText>
<reportElement uuid="7261c001-6771-47dc-9749-5e6f64fb86df" x="159" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[DESC]]></text>
</staticText>
<staticText>
<reportElement uuid="2b95c6fc-3fd9-4df1-89c6-5249173db3e1" x="287" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[DATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="23" splitType="Stretch">
<textField>
<reportElement uuid="becea2ba-40fd-4208-8191-c7475293ed5b" x="32" y="1" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="182efb3b-6a66-4634-be35-fe03e8a0cd45" x="159" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="bdb70a35-b4e6-4857-96c5-f607ee59bc07" x="287" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="15" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="6" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="7" splitType="Stretch"/>
</summary>
For sub report with the xml files as a datasource, you need to specify the datasource for the sub report.
Properties you need to have a look at are
Connection Type : Use a Datasource Expression
Connection / Datasource Expression :
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//YOUR_SUBREPORT_ENTITY").
You will need something similar to this
<dataSourceExpression><![CDATA[
((net.sf.jasperreports.engine.data.JRXmlDataSource)
$P{REPORT_DATA_SOURCE}).subDataSource("//YOUR_SUBREPORT_ENTITY") ]]>
</dataSourceExpression>
Maybe now its not actually for you, but someone it help.
All what need - its set datasource expression for subreport, how it realise:
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).datasource("YOUR_SUBREPORT_XPATH") ]]>
</dataSourceExpression>
Instead "YOUR_SUBREPORT_XPATH" use XPath that you set in subreport. In this case it will be "/REPORTDATA/GRID1/line"
In newer versions of Jasper (i used 6.x) is better and correct use .datasource(...) instead .subDataSource(...)
I am new to Jasper Reports. I have a report with 2 groups. Depending on the query, multiple pages are being printed.
1st Group Height -- 95 Points and 2nd Group Height -- 144 Points
I want these multiple pages to be printed in one page (I want to incorporate 5 pages in a page). Each page height is 239 Points. (Even if content of page is less than 239 Points, I want to keep the remaining part as blank and start the next page after 239 Points). I tried creating a Report and included the above report as a sub-report and set the height of main report as 1195 (239 * 5) Points. Still, these are being printed in different pages.
The result of export is:
The main report design is:
The first subreport design is:
The second subreport design is:
Please help me regarding this.
I've made a test based on your specifications and it seems to work just fine. I can give you a couple of pointers here.
In your main-report design, the height of the sub-report element doesn't matter as long as it is equal to the underlying band. If the sub-report element is shorter, the difference will appear in the result.
The page height of the sub-report doesn't matter, just the total height of the bands.
Check to make sure that the "Start on a new Page" option hasn't been selected on the groups that you have created. This is the most likely issue.
If the top 3 hasn't fixed your problem, look through the sample below and compare differences.
MainReport:
<?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="MainReport1" language="groovy" pageWidth="595" pageHeight="1195" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\Bizz\\Documents\\JasperReports\\"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<group name="Group1">
<groupExpression><![CDATA[$F{PRODUCT_ID}]]></groupExpression>
<groupHeader>
<band height="50">
<subreport>
<reportElement x="0" y="0" width="200" height="50"/>
<subreportParameter name="ProductID">
<subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport2.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
<group name="Group2">
<groupExpression><![CDATA["2"]]></groupExpression>
<groupHeader>
<band height="50">
<subreport>
<reportElement x="0" y="0" width="200" height="50"/>
<subreportParameter name="ProductID">
<subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band splitType="Stretch"/>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Subreport1:
<?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="MainReport1_subreport1" language="groovy" pageWidth="555" pageHeight="95" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="ProductID" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT
where
product_id = $P{ProductID}]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="95" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_ID]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_NAME]]></text>
</staticText>
<textField>
<reportElement x="100" y="20" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="40" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_COST]]></text>
</staticText>
<textField>
<reportElement x="100" y="40" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="60" width="200" height="35"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Subreport2:
<?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="MainReport1_subreport2" language="groovy" pageWidth="555" pageHeight="888" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="ProductID" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT
where
product_id = $P{ProductID}]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="144" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_ID]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_NAME]]></text>
</staticText>
<textField>
<reportElement x="100" y="20" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="40" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_COST]]></text>
</staticText>
<textField>
<reportElement x="100" y="40" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="60" width="302" height="84"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Hi every one I am using iReports for generating one of the reports and stuck at one place.
The situation is like this:
I am using one sub report in my main report and i want to return a variable (float) back to the main report from sub report after the query has been executed. And i'm just getting null values back to main report i have wasted 2 days googling and searching but problem is still there..
bellow is my dummy code of my JRXMLS (perfectly same) and snaps...
Main Report JRXML
<?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="anuj" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["/home/anuj/Reports/"]]></defaultValueExpression>
</parameter>
<queryString language="SQL">
<![CDATA[select * from "SensorType"]]>
</queryString>
<field name="SensorTypeId" class="java.lang.Integer"/>
<field name="SensorTypeName" class="java.lang.String"/>
<variable name="A" class="java.lang.Integer" resetType="None" calculation="System"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="23" splitType="Stretch">
<textField>
<reportElement x="71" y="3" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SensorTypeId}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="202" y="3" width="112" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SensorTypeName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="5" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="1" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch">
<subreport>
<reportElement x="183" y="16" width="257" height="26"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="A" toVariable="A"/>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "anuj_subreport1.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="71" y="22" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{A}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
Sub Report JRXML
<?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="anuj_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="149"/>
<queryString>
<![CDATA[select Sum("SensorTypeId") from "SensorType";]]>
</queryString>
<field name="sum" class="java.lang.Long"/>
<variable name="A" class="java.lang.Integer" resetType="None" calculation="System">
<variableExpression><![CDATA[$F{sum}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="169" y="59" width="100" height="20"/>
<textElement/>
<text><![CDATA[sum]]></text>
</staticText>
<textField>
<reportElement x="216" y="59" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{sum}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Thanks in advance..
Although the question is already answered, I would like to highlight the importance of having calculation="System" on the variable in the Main Report (the report calling the SubReport).
I wasted a lot of time before figuring this out...
In the dummy-code for Main Report JRXML above, the variable "A" correctly has calculation="System". NB: The answer by #GenericJon covers the variable in the SubReport.
In the subreport variable, you have calculation=System. This should be used when you are calculating the variable yourself using a scriptlet. You do not have an appropriate scriptlet attached to the report, so the variable is never being calculated.
You probably want to change the variable definition so that it is calculated at the start of the subreport, something like this:
<variable name="A" class="java.lang.Integer" resetType="Report" calculation="Nothing">
<variableExpression><![CDATA[$F{sum}]]></variableExpression>
</variable>
resetType="Report" will never reset the variable while the report is running.
calculation="Nothing" will evaluate the variableExpression for every row in the dataset.
These attributes could be omitted though, as they are the default values used. You should then find that the variable is initialised correctly.
From the JasperReports Ultimate Guide:
The value coming from the subreport is available only when the whole band containing the subreport is printed. If you need to print this value using a textfield placed in the same band as your subreport, set the evaluation time of the textfield to Band
i am agree with #bubba_hego99, the calculation type as below:
system no caculation, just set as system, or valued as other operator.
nothing no calulation, just set the variable.
sum execute sum($Feild("A")).
....
The detail you want to know other caculation, you should be to see the ireport document.
Note, in earlier versions of JasperReports:
When using a subreport returnValue, the variable returned must not be in the same band as the subreport itself.
The affectation is done I think at the end of the rendering of the band.
So add another band and use your variable inside.