I started working with subreports in JapserReports. At the beginning I would like to do something very simple.
This is xml code of my subreport:
<?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="Rb50dane" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" 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"/>
<field name="column01" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="22" splitType="Stretch">
<textField>
<reportElement x="208" y="0" width="257" height="22"/>
<box>
<pen lineWidth="3.25"/>
<topPen lineWidth="3.25"/>
<leftPen lineWidth="3.25"/>
<bottomPen lineWidth="3.25"/>
<rightPen lineWidth="3.25"/>
</box>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{column01}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
And this is part of my main report code:
<detail>
<band height="22" splitType="Stretch">
<subreport>
<reportElement x="208" y="0" width="257" height="22"/>
<dataSourceExpression><![CDATA[]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA["C:\\Users\\mg\\Jasper\\Rb50data.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
As you can see I do not use any parameter in my subreport. Unfortunately, in iReport after compiling my main report, subreport is not displayed, but when I try to run my subreport separately it works.
In my test I use empty data source. I just want to see the column with null value to find out whether the subreport works fine.
I'd try adding something in the dataSourceExpression of the parent report. Maybe send the whole data source by using *
Related
Can somebody show how to integrate josson library https://github.com/octomix/josson with JasperReports
Like if I pass JSON object in JasperReports parameter "jsonData". Now, I want to filter the JSON data based on gender say "M" and show in detail band.
JSON data
[{"id":1,"first_name":"Benny","last_name":"McGonigal","gender":"M"},
{"id":2,"first_name":"Calhoun","last_name":"Streeting","gender":"M"},
{"id":3,"first_name":"Birdie","last_name":"Mosen","gender":"F"},
{"id":4,"first_name":"Mariya","last_name":"Bugby","gender":"F"},
{"id":5,"first_name":"Anitra","last_name":"Benjafield","gender":"F"},
{"id":6,"first_name":"Corette","last_name":"Varren","gender":"F"},
{"id":7,"first_name":"Allister","last_name":"Summons","gender":"M"},
{"id":8,"first_name":"Arturo","last_name":"Adair","gender":"M"},
{"id":9,"first_name":"Opal","last_name":"Hannigan","gender":"F"},
{"id":10,"first_name":"Eberto","last_name":"Summergill","gender":"M"}]
Report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.20.0-2bc7ab61c56f459e8176eb05c7705e145cd400ad -->
<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="JSON" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8adeb6f4-1f01-46d3-96aa-fb2d321499be">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="jsonData" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["[{\"id\":1,\"first_name\":\"Benny\",\"last_name\":\"McGonigal\",\"gender\":\"M\"},{\"id\":2,\"first_name\":\"Calhoun\",\"last_name\":\"Streeting\",\"gender\":\"M\"},{\"id\":3,\"first_name\":\"Birdie\",\"last_name\":\"Mosen\",\"gender\":\"F\"},{\"id\":4,\"first_name\":\"Mariya\",\"last_name\":\"Bugby\",\"gender\":\"F\"},{\"id\":5,\"first_name\":\"Anitra\",\"last_name\":\"Benjafield\",\"gender\":\"F\"},{\"id\":6,\"first_name\":\"Corette\",\"last_name\":\"Varren\",\"gender\":\"F\"},{\"id\":7,\"first_name\":\"Allister\",\"last_name\":\"Summons\",\"gender\":\"M\"},{\"id\":8,\"first_name\":\"Arturo\",\"last_name\":\"Adair\",\"gender\":\"M\"},{\"id\":9,\"first_name\":\"Opal\",\"last_name\":\"Hannigan\",\"gender\":\"F\"},{\"id\":10,\"first_name\":\"Eberto\",\"last_name\":\"Summergill\",\"gender\":\"M\"}]"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="first_name" class="java.lang.String"/>
<field name="last_name" class="java.lang.String"/>
<field name="gender" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="31" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="185" height="30" uuid="da8853a9-3803-4f22-89ad-add2b4294923">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="3febe426-0ae6-4755-9762-06611a52ed51"/>
</reportElement>
<text><![CDATA[first_name]]></text>
</staticText>
<staticText>
<reportElement x="185" y="0" width="185" height="30" uuid="9c8a17bf-68ec-406e-84e5-347c6a12d3cb">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1a353093-c753-4c90-afb0-7542e9345c4d"/>
</reportElement>
<text><![CDATA[last_name]]></text>
</staticText>
<staticText>
<reportElement x="370" y="0" width="185" height="30" uuid="e3d8d1f8-3ebb-4b4e-8d39-080d61f258a0">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="47e0f941-3ec2-4ef7-8574-4661e4747d66"/>
</reportElement>
<text><![CDATA[gender]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="32" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="185" height="30" uuid="e119f67a-0f12-4b2b-baa5-839352ea2cd3">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="3febe426-0ae6-4755-9762-06611a52ed51"/>
</reportElement>
<textFieldExpression><![CDATA[$F{first_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="185" y="0" width="185" height="30" uuid="9d6eaa7c-1153-4e7a-8b93-3e84ca821228">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1a353093-c753-4c90-afb0-7542e9345c4d"/>
</reportElement>
<textFieldExpression><![CDATA[$F{last_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="370" y="0" width="185" height="30" uuid="b8148f4c-7e55-4df0-bdf6-92c32e8f1885">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="47e0f941-3ec2-4ef7-8574-4661e4747d66"/>
</reportElement>
<textFieldExpression><![CDATA[$F{gender}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Could anyone give a simple example to call a jasper report with subreport inside subreport from a java program. Something like this (Generate Jasper report with subreport from java):
JasperReport jasperMasterReport = JasperCompileManager.compileReport(masterReportSource);
JasperReport jasperSubReport1 = JasperCompileManager.compileReport(subReportSource1);
JasperReport jasperSubReport2 = JasperCompileManager.compileReport(subReportSource2);
Map<String, Object> parameters2 = new HashMap()<String, Object>;
parameters2.put("subreportParameter2", jasperSubReport2);
Map<String, Object> parameters1 = new HashMap()<String, Object>;
parameters1.put("subreportParameter1", JasperFillManager.fillReportToFile(jasperSubReport1, parameters2, connection));
JasperFillManager.fillReportToFile(jasperMasterReport, parameters1, connection);
MasterReport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-05-02T10:06:38 -->
<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="MasterReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5adfa1b1-651c-478e-a83b-6230d66dc454">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/>
<parameter name="subreportParameter1" class="net.sf.jasperreports.engine.JasperReport"/>
<queryString language="SQL">
<![CDATA[SELECT "PERSON"."ID",
"PERSON"."FIRST_NAME",
"PERSON"."LAST_NAME"
FROM "PERSON"]]>
</queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="FIRST_NAME" class="java.lang.String"/>
<field name="LAST_NAME" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="16" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="93" height="16" uuid="cde3f82c-d51e-43ef-a56e-fee3cb853b65"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[PERSONS:]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="80" splitType="Stretch">
<textField>
<reportElement x="0" y="20" width="30" height="20" uuid="9fbab9bb-55ec-44c0-badb-501a00334fe6"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="30" height="20" uuid="3c5afed0-442f-41de-9929-abdb8a218981"/>
<text><![CDATA[ID]]></text>
</staticText>
<textField>
<reportElement x="30" y="20" width="100" height="20" uuid="2561523d-322d-487d-89a2-be44804979ee"/>
<textFieldExpression><![CDATA[$F{FIRST_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="30" y="0" width="100" height="20" uuid="431ac382-603e-47a1-b4df-b9d744041718"/>
<text><![CDATA[FIRST NAME]]></text>
</staticText>
<textField>
<reportElement x="130" y="20" width="100" height="20" uuid="9b482687-49c6-49f7-b322-ba868e4ce748"/>
<textFieldExpression><![CDATA[$F{LAST_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="130" y="0" width="100" height="20" uuid="4532e6f3-58c0-4c24-aebc-a135309d94ba"/>
<text><![CDATA[LAST NAME]]></text>
</staticText>
<subreport>
<reportElement x="2" y="40" width="550" height="40" uuid="18ecc4c5-81a1-4ae3-b3f7-3bf10c627be8"/>
<subreportParameter name="PERSON_ID">
<subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{subreportParameter1}]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Subreport1.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-05-02T10:11:02 -->
<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="Subreport1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a0096e3a-50c2-49db-ba13-71afb020c425">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/>
<parameter name="PERSON_ID" class="java.math.BigDecimal"/>
<parameter name="subreportParameter2" class="net.sf.jasperreports.engine.JasperReport"/>
<queryString language="SQL">
<![CDATA[SELECT "PHONE"."ID",
"PHONE"."PARENT_ID",
"PHONE"."PHONE_NUMBER"
FROM "PHONE"
WHERE "PHONE"."PARENT_ID" = $P{PERSON_ID} ]]>
</queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="PARENT_ID" class="java.math.BigDecimal"/>
<field name="PHONE_NUMBER" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20" uuid="26c75f7b-f80c-41ca-a3fc-eb3317026efd"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[PHONES:]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="70" splitType="Stretch">
<textField>
<reportElement x="90" y="0" width="454" height="20" uuid="76669766-73b0-47f1-bfff-9337428a4776"/>
<textFieldExpression><![CDATA[$F{PHONE_NUMBER}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="90" height="20" uuid="f925e71b-16fe-42ae-8895-143fb886eb63"/>
<text><![CDATA[PHONE NUMBER:]]></text>
</staticText>
<subreport>
<reportElement x="0" y="30" width="544" height="40" uuid="029f8258-5205-4e91-ae08-e8d8ec55f5e9"/>
<subreportParameter name="PHONE_ID">
<subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{subreportParameter2}]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Subreport2.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-05-02T10:13:15 -->
<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" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9bd68d39-b94b-4e26-94ea-e0dc1e55f226">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/>
<parameter name="PHONE_ID" class="java.math.BigDecimal"/>
<queryString language="SQL">
<![CDATA[SELECT "CONTACT_LOG"."ID",
"CONTACT_LOG"."R_PHONE_ID",
"CONTACT_LOG"."DSC"
FROM "CONTACT_LOG"
WHERE "CONTACT_LOG"."R_PHONE_ID" = $P{PHONE_ID}]]>
</queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="R_PHONE_ID" class="java.math.BigDecimal"/>
<field name="DSC" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="15" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="15" uuid="0779105f-7c86-4541-906f-ea473cdc3ff5"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[CONTACTS:]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="102" y="0" width="448" height="30" uuid="67919643-f890-4121-ac18-59f87b0752f3"/>
<textFieldExpression><![CDATA[$F{DSC}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="2" y="0" width="100" height="30" uuid="7c3824f0-41ff-4e53-8278-dcd0e535efd4"/>
<text><![CDATA[COMMENT:]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Thanks.
You can pass the subreport path as main report parameter and get number of subreports like this.
String file = /pathToMainReport/name.jrxml;
String subreport1 = /pathToSubReport/name1.jasper;
String subreport2 = /pathToSubReport/name2.jasper;
JasperReport jreport = JasperCompileManager.compileReport(file);
Map<String, Object> map = new HashMap<String, Object>();
map.put("SUBREPORT_DIR1", subreport1);
map.put("SUBREPORT_DIR2", subreport2);
JasperPrint jprint = JasperFillManager.fillReport(jreport, map, connection);
I have a jrxml file. In this file I have a column with hyperlink to same report. But when I click on this link from any page jasper server loads first page. How can I load the same page from which I clicked on the link?
Here is the example 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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a5de7f4f-53e0-43ce-a41d-cd01ab98e889">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT * from employee]]>
</queryString>
<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">
<textField isStretchWithOverflow="true">
<reportElement x="21" y="41" width="110" height="20" uuid="ac484988-9581-4b7e-bf5d-2585ae2a1365"/>
<textElement textAlignment="Center">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[($F(roll_no))]]></textFieldExpression>
</textField>
<image hAlign="Center" hyperlinkType="ReportExecution">
<reportElement mode="Transparent" x="481" y="41" width="20" height="20" uuid="5a15a90d-499d-47ed-a768-4f703c6c5ed4"/>
<imageExpression><![CDATA["/datasources/Images/check"]]></imageExpression>
<hyperlinkParameter name="_report">
<hyperlinkParameterExpression><![CDATA["/root/reports/myReport"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
</image>
<staticText>
<reportElement x="463" y="23" width="65" height="18" uuid="f13d3810-4106-42d8-acdc-0eeb8033cd32"/>
<textElement textAlignment="Center">
<font size="12" isBold="true" isUnderline="false"/>
</textElement>
<text><![CDATA[Accept]]></text>
</staticText>
<staticText>
<reportElement x="21" y="23" width="110" height="18" uuid="fbb887ce-fab7-4142-8de2-f7f565e1bb18"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Staus]]></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>
You need to create an anchor to the points in your report you want to be able to jump to, and specify these in your hyperlink definitions.
Cannot post an example but this should be enough info to get you started if you're using iReport or Jaspersoft Studio to author your reports.
I'm trying to generate report using XML data source. My input xml file has 4 lines. But JR engine generates report contains only 1st row.
I have <detail> <band> ... </band> </detail> section to get the data
My jrxml file looks like this
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="simpleReport">
<queryString language="xPath"><![CDATA[/response/results]]></queryString>
<field name="field" class="java.lang.String">
<fieldDescription><![CDATA[//field]]></fieldDescription>
</field>
<field name="count" class="java.lang.String">
<fieldDescription><![CDATA[//field[#count]]]></fieldDescription>
</field>
<title>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="180" height="15"/>
<textElement/>
<text><![CDATA[Report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band/>
</pageHeader>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[Event Name]]></text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[Count]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="180" y="0" width="180" height="15"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="360" y="0" width="180" height="15"/>
<textElement/>
<textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="40" height="15"/>
<textElement/>
<text><![CDATA[Page:]]></text>
</staticText>
<textField>
<reportElement x="40" y="0" width="100" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
My input xmls is
<response id="1074200577">
<results id1="0" id2="0">
<field count="7556">one</field>
<field count="7524">two</field>
<field count="7402">three</field>
<field count="7304">four</field>
</results>
</response>
My Java client is
JasperCompileManager.compileReportToFile(inpuutjrxml, outputjasper);
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile));
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));
How to get all values from input xml?
Also how to get the id value for ?
For first xml row <field count="7556">one</field>
<fieldDescription><![CDATA[//field[#count]]]></fieldDescription>
<fieldDescription><![CDATA[//field]]></fieldDescription>
gives same data as "One"
You can try this query (XPath):
/response/results/field
and this fields declaration:
<field name="field" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<field name="count" class="java.lang.String">
<fieldDescription><![CDATA[#count]]></fieldDescription>
</field>
Using iReport
The full jrxml file for trying from iReport:
<?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="xml_missing_rows" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="09291847-62d6-4f2e-bf29-6db3230ce9a4">
<queryString language="xPath">
<![CDATA[/response/results/field]]>
</queryString>
<field name="field" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<field name="count" class="java.lang.String">
<fieldDescription><![CDATA[#count]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The result for your input data will be (via preview in iReport):
Note: I've used the iReport 5.2.0
Using Java code
You should modify your code as:
JRXmlDataSource source = new JRXmlDataSource(new File(sourceFile), "/response/results/field");
HashMap<String, Object> params = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(outputjasper, params, source);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(pefoutput));
In this case we are using the JRXmlDataSource(java.io.File file,
java.lang.String selectExpression) constructor. We are passing the query with data.
The jrxml should be:
<?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="XMLDSSample" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="09291847-62d6-4f2e-bf29-6db3230ce9a4">
<field name="field" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<field name="count" class="java.lang.String">
<fieldDescription><![CDATA[#count]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="30be33c9-3e8c-4b8f-89b7-c2cdafd91615" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
As you can see I've removed the queryString from the template - we are passing query in Java code.
In my situation, I wrongly put the textField elements inside the summary elements. I was able to solve it by moving the textFields inside the detail elements.
Why my subreport it isn't shown? Look, the JRXML code is very simple.
When I press the view button in iReport only the main report is shown.
The two subreports aren't shown.
Any help is welcome.
report1_subreport1.jrxml:contains only a static text in the title band
<?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_subreport1"language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="05f9b4fc-35fa-4335-8fd3-a02a78526a7c">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement uuid="b9a3b1af-3d85-4902-a374-0674a0ea5c9f" x="0" y="7" width="218" height="72"/>
<textElement/>
<text><![CDATA[Mensage1]]></text>
</staticText>
</band>
</title>
</jasperReport>
report1.jrxml : contains a static text and two subreports, the same defined early.
<?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" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" uuid="cb5ca789-5eeb-4fce-914b-626d1da98104">
<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/david/teste/"]]></defaultValueExpression>
</parameter>
<queryString language="XPath">
<![CDATA[]]>
</queryString>
<title>
<band height="61" splitType="Stretch">
<subreport>
<reportElement uuid="b762ee33-6259-4103-92c0-f0dda0139a2f" x="0" y="0" width="555" height="61"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report1_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</title>
<columnHeader>
<band height="61" splitType="Stretch">
<textField>
<reportElement uuid="af42ea5b-3b1e-4701-8077-6bd72597c929" x="0" y="0" width="555" height="61"/>
<textElement/>
<textFieldExpression><![CDATA["Main Message"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="61" splitType="Stretch">
<subreport runToBottom="false">
<reportElement uuid="b762ee33-6259-4103-92c0-f0dda0139a2f" x="0" y="0" width="555" height="61"/>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report1_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
I figure out the problem.
The fields "When no data" were set to "no pages" and should be "All Section, No Detail".
Another reason is the second subreport is in deatail band thus won't be printed.
I didn't test in runtime, only in iReport however i think it will run.