JasperReports: JRDataSource.subDataSource shows undefined - jasper-reports

I am following this tutorial to create my reports using iReport.
I have already created a couple of reports using the guidelines mentioned.
But in a new report, when I set the DataSource of the ListComponent Jasper reports the following error to me:
The method subDataSource(String) is undefined for the type JRDataSource                 value = ((net.sf.jasperreports.engine.JRDataSource)parameter_REPORT_DATA_SOURCE.getValue()).subDataSource("/items/invoices"); //$JR_EXPR_ID=11$
I tried to look up in the docs, It does mention that JRDataSource doesn't have any such methods. But, I have followed this tutorial earlier and made reports.
This is the JRXML code of the report where I am stuck:
<?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="product-wise-sales-analysis" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a8a1a939-18a1-4ecf-8c4c-9f7b556b5ce3">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="invoices" uuid="9d9c4386-0f01-4f9f-9b17-12906b566f63">
<queryString language="xPath">
<![CDATA[/data/items/invoices]]>
</queryString>
<field name="invoiceId" class="java.lang.String">
<fieldDescription><![CDATA[invoiceId]]></fieldDescription>
</field>
<field name="salesInvoiceDate" class="java.lang.String">
<fieldDescription><![CDATA[salesInvoiceDate]]></fieldDescription>
</field>
<field name="partyName" class="java.lang.String">
<fieldDescription><![CDATA[partyName]]></fieldDescription>
</field>
<field name="quantity" class="java.lang.String">
<fieldDescription><![CDATA[quantity]]></fieldDescription>
</field>
<field name="rate" class="java.lang.String">
<fieldDescription><![CDATA[rate]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/data/items]]>
</queryString>
<field name="productCatlgNo" class="java.lang.String">
<fieldDescription><![CDATA[productCatlgNo]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="groupName" class="java.lang.String">
<fieldDescription><![CDATA[groupName]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="23" splitType="Stretch">
<staticText>
<reportElement x="0" y="2" width="100" height="20" uuid="b14d57a3-c78e-4121-ac21-955b4ab431f0"/>
<text><![CDATA[productCatlgNo]]></text>
</staticText>
<staticText>
<reportElement x="147" y="2" width="100" height="20" uuid="c009d720-b224-4595-9761-89447d437dc3"/>
<text><![CDATA[description]]></text>
</staticText>
<staticText>
<reportElement x="341" y="0" width="100" height="20" uuid="f22f2f3f-885e-4ffd-bd2f-b69025a46c2d"/>
<text><![CDATA[groupName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="34" splitType="Stretch">
<textField>
<reportElement x="147" y="0" width="194" height="12" uuid="383b8740-6b4d-4ddd-9e85-6aa45a08c464"/>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="147" height="12" uuid="ebd965f4-5684-49b8-8ed4-e11e43d64230"/>
<textFieldExpression><![CDATA[$F{productCatlgNo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="341" y="0" width="209" height="12" uuid="4b98a152-6c2e-4335-835a-9288c179df5a"/>
<textFieldExpression><![CDATA[$F{groupName}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="12" width="555" height="21" uuid="786c54cf-6dc1-4daf-a174-694c24cfd27b"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="invoices" uuid="c61741af-4e58-4bb6-a18b-468a29c02b14">
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/items/invoices")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="21" width="555">
<textField>
<reportElement x="5" y="0" width="100" height="20" uuid="c3923524-ac87-4a59-a4d0-89d4c6ade197"/>
<textFieldExpression><![CDATA[$F{invoiceId}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Any ideas why this is happening?

I figured this out.
For some reason, I had to cast the DataSource of the ListComponent to a JRXmlDataSource object. (I haven't done this casting in my previous reports)
So the expression for DataSource in the ListComponent would be:
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/items/invoices")
instead of:
$P{REPORT_DATA_SOURCE}).subDataSource("/items/invoices")

In my case, the answer was to select "groovy" as the language used in the report.
Properties -> Report -> Language

Related

Jasper with odoo display M2O and O2M fields

i am trying to create a report in iReport in integration with odoo using XML data source. Now the problem is i get null values for the M2O and O2M fileds.
how should i get the values for those fields in my report?
thanks in advance.
this is the jrxml of my report. here title holds the id but i want title-name instead of its id.
<?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="report2" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1cea34a0-6df0-4b5c-bdf1-5396f16c69b6">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[]]>
</queryString>
<field name="id" class="java.lang.String">
<fieldDescription><![CDATA[/data/record/id]]></fieldDescription>
</field>
<field name="Name-display_name" class="java.lang.String">
<fieldDescription><![CDATA[/data/record/Name-display_name]]> </fieldDescription>
</field>
<field name="State-state_id" class="java.lang.String">
<fieldDescription><![CDATA[/data/record/State-state_id]]></fieldDescription>
</field>
<field name="Title-title" class="java.lang.String">
<fieldDescription><![CDATA[/data/record/Title-title]]> </fieldDescription>
</field>
<variable name="variable1" 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 uuid="cc4e4037-d5b4-4779-9323-35175b9d3996" mode="Transparent" x="19" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[/data/record/id]]></text>
</staticText>
<staticText>
<reportElement uuid="7d30c360-83e0-4f99-9f46-7fa942a9fa2c" mode="Transparent" x="142" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[/data/record/Name-display_name]]></text>
</staticText>
<staticText>
<reportElement uuid="24237311-4f91-49d9-977d-f5d2d303c46b" x="367" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[/data/record/Title-title]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement uuid="80e11f37-ce2b-4c66-a868-30b5695cd5f9" mode="Transparent" x="19" y="11" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="dfa7b27b-44e7-494c-8653-7dab71764c07" mode="Transparent" x="142" y="31" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Name-display_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="9d67e3e3-503d-41f5-beb3-d657f8c48306" x="367" y="28" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Title-title}]]></textFieldExpression>
<patternExpression><![CDATA[$F{Title-title}]]></patternExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>

How to create a jasper report that manage overflow in next page?

i would like to know if is possible have a report that has a lot of fields that manage automatically the overflow in other page. I would put every field in detail tag and i would like that when there is some element that goes outside of detail area, it could be appear in the next one. Below i posted my jasper report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.0.final using JasperReports Library version 6.0.0 -->
<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="SvamaTemplate" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="335f8e22-f47d-4b34-abcd-a6682c0cf7b4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="SvamaTemplateXML"/>
<queryString language="xPath">
<![CDATA[/]]>
</queryString>
<field name="id" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/#id]]></fieldDescription>
</field>
<field name="potenziale_residuo_vpot" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="potenziale_residuo_vpot"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="supporto_rete_sociale" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="supporto_rete_sociale"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="pulizia_casa" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="pulizia_casa"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="lavanderia" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="lavanderia"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="effettuazione_acquisti" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="effettuazione_acquisti"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="bagno" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="bagno"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="toiletta" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="toiletta"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="abbigliamento1" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="abbigliamento1"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="uso_wc" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="uso_wc"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="assuzione_medicinali" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="assuzione_medicinali"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="trasferimenti" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="trasferimenti"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="deambulazione1" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="deambulazione1"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="gestione_denaro" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="gestione_denaro"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="sostegno_psicoaffettivo" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="sostegno_psicoaffettivo"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="supervisione_diurna" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="supervisione_diurna"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<field name="supervisione_notturna" class="java.lang.String">
<fieldDescription><![CDATA[/svama/sections/section/subsection/selectOneRadio[#id="supervisione_notturna"]/items/item[#selected="true"]/value/text()]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="47" splitType="Stretch">
<staticText>
<reportElement x="230" y="8" width="100" height="30" uuid="91c6fde2-503f-4228-8cf0-e2878b9fdb3b"/>
<textElement textAlignment="Center">
<font size="20" isBold="true"/>
</textElement>
<text><![CDATA[SVAMA]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="13" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="13" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="270" splitType="Stretch">
<textField>
<reportElement x="130" y="120" width="424" height="30" uuid="74e0b517-f4c9-4679-a8d2-54e7f4582a3e"/>
<textFieldExpression><![CDATA[$F{pulizia_casa}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="120" width="110" height="30" uuid="40f82bd5-9d95-45b3-b21d-c7f738c576c5"/>
<text><![CDATA[pulizia_casa]]></text>
</staticText>
<textField>
<reportElement x="130" y="200" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{effettuazione_acquisti}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="200" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[effettuazione_acquisti]]></text>
</staticText>
<!-- break is attempt, i don't know what should put here -->
<break>
<reportElement x="0" y="270" width="517" height="1" uuid="08ff5b1a-7ff4-4848-ba95-e9ce31d0d44e"/>
</break>
<staticText>
<reportElement x="10" y="280" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[toiletta]]></text>
</staticText>
<textField>
<reportElement x="130" y="280" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{toiletta}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="320" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[abbigliamento1]]></text>
</staticText>
<textField>
<reportElement x="130" y="320" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{abbigliamento1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="360" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[uso_wc]]></text>
</staticText>
<textField>
<reportElement x="130" y="360" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{uso_wc}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="440" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[trasferimenti]]></text>
</staticText>
<textField>
<reportElement x="130" y="440" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{trasferimenti}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="520" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[gestione_denaro]]></text>
</staticText>
<textField>
<reportElement x="130" y="520" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{gestione_denaro}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="560" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[sostegno_psicoaffettivo]]></text>
</staticText>
<textField>
<reportElement x="130" y="560" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{sostegno_psicoaffettivo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="640" width="110" height="30" uuid="e2d4b4b2-5c98-4041-9b94-36aa7e2c53e5"/>
<text><![CDATA[supervisione_notturna]]></text>
</staticText>
<textField>
<reportElement x="130" y="640" width="424" height="30" uuid="f8c91c60-26bb-419e-87a7-8b2dd158b83b"/>
<textFieldExpression><![CDATA[$F{supervisione_notturna}]]></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>
Does anyone have any idea? Thanks in advance.
Try changing:
<detail>
<band height="270" splitType="Stretch">
to
<detail>
<band height="270" splitType="Immediate">
In case it starts printing a blank page at the end, you might want to use:
<detail>
<band height="270" splitType="Prevent">
Instead

net.sf.jasperreports.engine.JRException:Resource not found

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.

Subreport using XML file datasource don't work

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(...)

Jasper Reports: How can I print multiple pages in one page

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>