I have 2 groups, both will show the same 2 records (from the sql output) but grouped differently and shows different fields.
Output:
The 2nd result of group 1 is between the results of group 2. This is how Jaspersoft works.
But does someone have an idea how to keep the group results with eachother?
Group 1: result 1
Group 1: result 2
Group 2: result 1
Group 2: result 2
Any help or tips are appreciated.
[1]https://i.stack.imgur.com/509cP.jpg
Jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.2.final using JasperReports Library version 4.7.0 -->
<!-- 2017-08-11T16:19:29 -->
<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_3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a75576f0-e223-4e8a-8d52-67936178ea31">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="test"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="from_name" class="java.lang.String"/>
<field name="from_name2" class="java.lang.String"/>
<field name="undgcode" class="java.lang.String"/>
<field name="product_item_id" class="java.lang.String"/>
<group name="Group1">
<groupExpression><![CDATA[$F{product_item_id}]]></groupExpression>
<groupHeader>
<band height="50" splitType="Prevent">
<textField>
<reportElement isPrintRepeatedValues="false" x="40" y="10" width="220" height="30" uuid="ce52a200-b3dd-4b9b-bee4-30cc9db15aa5"/>
<textFieldExpression><![CDATA[$F{from_name}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<group name="Group2" keepTogether="true">
<groupExpression><![CDATA[$F{undgcode}]]></groupExpression>
<groupHeader>
<band height="64">
<staticText>
<reportElement x="140" y="10" width="100" height="30" uuid="28d2e565-98d6-4714-8420-81a3819ab46a"/>
<text><![CDATA[Static Text]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="50" splitType="Prevent">
<textField>
<reportElement isPrintRepeatedValues="false" x="40" y="10" width="220" height="30" uuid="857197bd-e4b6-404b-a527-19e63dd02a94">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{from_name2}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</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"/>
</columnHeader>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Related
Looking for the best way to solve my dilemma. I am building a report and the data source that is being used is JSON <- Not much experience with JSON.
This is how data looks coming across to me via JSON
Parent
Child
Child (NEED SOME FIELDS HERE FOR HEADER)
FINAL CHILD (Need Fields In Here) (Setup as array bc multiple of Final Child)
FINAL CHILD
FINAL CHILD and so on (FINAL CHILD will be repeating in the Detail section.)
ALSO FINAL CHILD IS SETUP IN ARRAY FOR EACH FINAL CHILD
Currently, I have built a master and subreport. I do not need to pass any data because of the parent only has children... but could not get it working where the detail section of the master report would cycle through all the Final Children.
Master Report PreView:
SubReport PreView:
No matter what I do to the sizing, I cannot get it to shrink down in size and compactness...
Master Report Code
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<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="Test4BD" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="65794bef-41ec-4ebe-9237-6c5db5cb403c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="BD JSON Data Adapter"/>
<queryString language="json">
<![CDATA[tXML.Message.InboundReportXML.MESSAGEDATA.ASNDATA.INBOUNDHEADER]]>
</queryString>
<field name="ASNID" class="java.lang.String">
<fieldDescription><![CDATA[ASNID]]></fieldDescription>
</field>
<field name="ASN" class="java.lang.String">
<fieldDescription><![CDATA[ASN]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="7" splitType="Stretch"/>
</title>
<pageHeader>
<band height="14" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="62" splitType="Stretch">
<textField>
<reportElement x="70" y="0" width="100" height="30" uuid="0f247a53-6ea3-462d-a655-0e3f02f2b611"/>
<textFieldExpression><![CDATA[$F{ASNID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="330" y="0" width="100" height="30" uuid="2c72da14-4800-4d2c-af67-58d27232133d"/>
<textFieldExpression><![CDATA[$F{ASN}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="75" splitType="Stretch">
<subreport>
<reportElement x="40" y="0" width="460" height="70" uuid="684434fc-a528-4e65-b7e8-6192048ae611"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportExpression><![CDATA["SubReport2.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>
SubReport:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<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="SubReport2" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2d15bbaf-6da1-4158-83b1-6a069fa6144b">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="BD JSON Data Adapter"/>
<queryString language="json">
<![CDATA[tXML.Message.InboundReportXML.MESSAGEDATA.ASNDATA.INBOUNDHEADER.INBOUNDDETAILS]]>
</queryString>
<field name="ASNDETAILID" class="java.lang.String">
<fieldDescription><![CDATA[ASNDETAILID]]></fieldDescription>
</field>
<field name="LINENBR" class="java.lang.String">
<fieldDescription><![CDATA[LINENBR]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="8" splitType="Stretch"/>
</title>
<pageHeader>
<band height="9" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="32" splitType="Stretch">
<staticText>
<reportElement x="84" y="0" width="100" height="30" uuid="3b17e526-5b45-45db-b75f-4a86a1608bec"/>
<text><![CDATA[ASNDETAILID]]></text>
</staticText>
<staticText>
<reportElement x="310" y="0" width="100" height="30" uuid="cd6e9ad5-60a5-4041-894d-970faa1d4bd5"/>
<text><![CDATA[LINENBR]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="33" splitType="Stretch">
<textField>
<reportElement x="70" y="0" width="100" height="30" uuid="e8036cc3-bddc-47d7-9686-bbea50bc7f1c"/>
<textFieldExpression><![CDATA[$F{ASNDETAILID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="210" y="0" width="100" height="30" uuid="5f3a97c2-6f8e-4458-8f9e-c13890a6b308"/>
<textFieldExpression><![CDATA[$F{LINENBR}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="10" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="7" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="8" splitType="Stretch"/>
</summary>
</jasperReport>
I am open to all suggestions... again, very little experience with JSON and Jasper... especially around subreports... I was hoping I would not even need a subreport.
In Subreport, delete all bands except column header and detail .
from properties, make all the margins to zero.
In main report, make column header height = field height
and delete all other bands.
This is all basic alignment.
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
My program generates an error for arabic letter :
cannot assign instance of net.sf.jasperreports.engine.base.JRBaseStaticText to field
net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type
net.sf.jasperreports.engine.JRParagraphContainer in instance of
net.sf.jasperreports.engine.base.JRBaseParagraph
I am using:
iReport 4.0.2
Windows XP
jasperreports-fonts-4.0.2.jar
jasperreports 4.0.2.jar
jasperreports-extensions-3.5.3
My .jrxml file is:
<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="strTitle" class="java.lang.String"/>
<field name="vchDhirams" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="21" splitType="Stretch">
<staticText>
<reportElement x="221" y="1" width="100" height="20"/>
<textElement markup="none"/>
<text><![CDATA[$P{strTitle}]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="37" splitType="Stretch">
<staticText>
<reportElement x="294" y="17" width="135" height="20"/>
<textElement>
<font pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[ستلام قسيمة]]></text>
</staticText>
</band>
</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>
Where is my fault? Please suggest me.
Thanks in advance.
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>
I'm trying to find out how to use a string collection as a datasource in JasperReports.
I guess I found the solution, but I can't get this to work, can anyone assist me?
set as datasource the special data source JREmptyDatasource( $F{my_collection}.size() )
This creates an empty data set with the same size of records as the collection.
Pass the $F{my_collection} as parameter to the sub dataset (using the data set run of the List).
To print the current element of the collection:
$P{my_collection_param}.get( $V{REPORT_COUNT} )
<?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="report1" 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"/>
<subDataset name="dataset1">
<parameter name="my_collection_param" class="java.util.Collection" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{my_collection}]]></defaultValueExpression>
</parameter>
</subDataset>
<parameter name="my_collection" class="java.util.Collection">
<defaultValueExpression><![CDATA["anna"]]></defaultValueExpression>
</parameter>
<field name="my_collection" class="java.util.Collection">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<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"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement x="51" y="30" width="400" height="50"/>
<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" printOrder="Vertical">
<datasetRun subDataset="dataset1">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($F{my_collection}.size())]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="50" width="0">
<textField>
<reportElement x="159" y="24" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{my_collection_param}.get( $V{REPORT_COUNT} )]]></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>
I guess your hack of using JREmptyDataSource is good by definition, if it works.
But you'll find that things are lot easier if you use this instead:
new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($P{my_collection_param})