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);
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>
I'm triying to parse an Json from spring to Jaspersoft, so I did the following:
JSONObject json = new JSONObject();
json.put("t", tickets);
json.put("totalAmount", df.format(totalAmount));
mapper.writeValue(jsonFile, json.toMap());
JsonDataSource source = new JsonDataSource(jsonFile);
JasperPrint print = JasperFillManager.fillReport(report, parameters, source);
and this create to me and a Json with the following information:
{
"t": [
{
"id": 5,
"number": 666,
"taxpayer": {
"name": "rodrigo",
"idAtmTaxpayer": null,
"cuit": "20408980675",
"email": "rodrigo.rodriguez#marandu.com.ar"
}
}
],
"totalAmount": "195626,92"
}
so, my doubt is: how I can show this information in Jaspersoft, without using subreports.
If somebody can help me I'll be very greatful.
The jxrml in Jasper is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<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="paidTicketsReport.jrxml" pageWidth="612" pageHeight="1008" whenNoDataType="AllSectionsNoDetail" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" uuid="b92698d7-fb13-42ad-9def-91a4029def19">
<parameter name="gob_logo" class="java.lang.String"/>
<parameter name="ipa_logo" class="java.lang.String"/>
<queryString language="JSON">
<![CDATA[t]]>
</queryString>
<field name="id" class="java.lang.Long">
<fieldDescription><![CDATA[id]]></fieldDescription>
</field>
<field name="number" class="java.lang.Long">
<fieldDescription><![CDATA[number]]></fieldDescription>
</field>
<field name="nameTaxpayer" class="java.lang.String">
<fieldDescription><![CDATA[taxpayer.name]]></fieldDescription>
</field>
<field name="idAtmTaxPayer" class="java.lang.Long">
<fieldDescription><![CDATA[taxpayer.idAtmTaxPayer]]></fieldDescription>
</field>
<field name="cuitTaxpayer" class="java.lang.String">
<fieldDescription><![CDATA[taxpayer.cuit]]></fieldDescription>
</field>
<field name="emailTaxpayer" class="java.lang.String">
<fieldDescription><![CDATA[taxpayer.email]]></fieldDescription>
</field>
<field name="amount" class="java.lang.String">
<fieldDescription><![CDATA[amount]]></fieldDescription>
</field>
Put TextFields whose expression is equal to your fields, e.g. $F{idAtmTaxPayer} in some band of your report, e.g. detail band.
This worked for me. Obviously, because you use t as the root of your data, the field "totalAmount" will not work.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f -->
<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="jsonTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="14c14d57-90eb-48b3-8c1c-cf5fa89e25ab">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="jsonData"/>
<queryString language="json">
<![CDATA[t]]>
</queryString>
<field name="id" class="java.lang.Integer">
<property name="net.sf.jasperreports.json.field.expression" value="id"/>
<fieldDescription><![CDATA[id]]></fieldDescription>
</field>
<field name="number" class="java.lang.Integer">
<property name="net.sf.jasperreports.json.field.expression" value="number"/>
<fieldDescription><![CDATA[number]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="taxpayer.name"/>
<fieldDescription><![CDATA[taxpayer.name]]></fieldDescription>
</field>
<field name="idAtmTaxpayer" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="taxpayer.idAtmTaxpayer"/>
<fieldDescription><![CDATA[taxpayer.idAtmTaxpayer]]></fieldDescription>
</field>
<field name="cuit" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="taxpayer.cuit"/>
<fieldDescription><![CDATA[taxpayer.cuit]]></fieldDescription>
</field>
<field name="email" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="taxpayer.email"/>
<fieldDescription><![CDATA[taxpayer.email]]></fieldDescription>
</field>
<columnHeader>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="95" height="30" uuid="dbf8388b-5025-4a17-807d-6c0a9a26d7f4">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="43fb794c-b551-4cdf-8ca2-a6e5556583e1"/>
</reportElement>
<text><![CDATA[id]]></text>
</staticText>
<staticText>
<reportElement x="95" y="0" width="92" height="30" uuid="8a47733e-b942-4f36-9a86-607d7f2708c4">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5b03c677-664e-46be-b72d-b0945b895ab7"/>
</reportElement>
<text><![CDATA[number]]></text>
</staticText>
<staticText>
<reportElement x="187" y="0" width="92" height="30" uuid="c309a2e4-a787-4fef-9d57-5f67cfbe8a85">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1069cfbe-9bb4-4f30-a540-d111361ddb46"/>
</reportElement>
<text><![CDATA[name]]></text>
</staticText>
<staticText>
<reportElement x="279" y="0" width="92" height="30" uuid="965e14eb-cd9f-4882-a57d-cd67afe9df00">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="ffd06315-cbb2-455d-908a-cb5b465e4a5d"/>
</reportElement>
<text><![CDATA[idAtmTaxpayer]]></text>
</staticText>
<staticText>
<reportElement x="371" y="0" width="92" height="30" uuid="8478944a-471a-464e-acb3-d8631608bb65">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4385b16b-71dd-4ad4-ad5f-f03e18328647"/>
</reportElement>
<text><![CDATA[cuit]]></text>
</staticText>
<staticText>
<reportElement x="463" y="0" width="92" height="30" uuid="22d39e8e-e230-4b28-86f8-06ba6aa95b0e">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9d594517-19e9-4187-9f77-ad7a0228557e"/>
</reportElement>
<text><![CDATA[email]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="95" height="30" uuid="45e4e430-802a-45de-95cf-5f199b5c8790">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="43fb794c-b551-4cdf-8ca2-a6e5556583e1"/>
</reportElement>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="95" y="0" width="92" height="30" uuid="e6e18897-08ce-4a2d-831b-429338ad5ee8">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5b03c677-664e-46be-b72d-b0945b895ab7"/>
</reportElement>
<textFieldExpression><![CDATA[$F{number}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="187" y="0" width="92" height="30" uuid="2b8f4467-21a0-4bf7-9575-6fb0b0222d3e">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1069cfbe-9bb4-4f30-a540-d111361ddb46"/>
</reportElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="279" y="0" width="92" height="30" uuid="544e5c63-f8df-4a96-9391-827acd4a9c8f">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="ffd06315-cbb2-455d-908a-cb5b465e4a5d"/>
</reportElement>
<textFieldExpression><![CDATA[$F{idAtmTaxpayer}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="371" y="0" width="92" height="30" uuid="87cf1ef2-db55-4a16-82ec-c838aa5606b2">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4385b16b-71dd-4ad4-ad5f-f03e18328647"/>
</reportElement>
<textFieldExpression><![CDATA[$F{cuit}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="463" y="0" width="92" height="30" uuid="2dc4fc4c-a687-4df0-bf4c-78bad2f76d20">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9d594517-19e9-4187-9f77-ad7a0228557e"/>
</reportElement>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
My jasper data source is JRBeanCollectionDataSource and input is following collection.
[SampleData [SerialNo=1,code=123,price=20],SampleData [SerialNo=2,code=234,price=20]].
Code snippet :
<?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="custom" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a3860b7-4c46-41ea-aae9-7f02e3679927">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="SerialNo" class="java.lang.String">
<fieldDescription><![CDATA[SerialNo]]></fieldDescription>
</field>
<field name="code" class="java.lang.String">
<fieldDescription><![CDATA[code]]></fieldDescription>
</field>
<field name="price" class="java.lang.Long">
<fieldDescription><![CDATA[price]]></fieldDescription>
</field>
<title>
<band height="22" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
<text><![CDATA[HDR]]></text>
</staticText>
<textField>
<reportElement x="22" y="0" width="130" height="20" uuid="f653a4ef-7863-4ea2-bb52-0cfa38d26ef0"/>
<textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="152" y="0" width="130" height="20" uuid="409ca2ad-ccf8-4007-bf41-ca67fee156fe"/>
<text><![CDATA[Rupees]]></text>
</staticText>
</band>
</title>
<detail>
<band height="22" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
<text><![CDATA[BDY]]></text>
</staticText>
<textField>
<reportElement x="22" y="0" width="130" height="20" uuid="f653a4ef-7863-4ea2-bb52-0cfa38d26ef0"/>
<textFieldExpression><![CDATA[$F{SerialNo}!=null?$F{SerialNo}:"-"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="152" y="0" width="130" height="20" uuid="ed37edb9-bb8f-43bf-904f-6ca5b5941aea"/>
<textFieldExpression><![CDATA[$F{code}!=null?$F{code}:"-"]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="22" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
<text><![CDATA[TRL]]></text>
</staticText>
<textField>
<reportElement x="22" y="0" width="130" height="20" uuid="adcc7751-da03-4141-9045-821960ce77c7"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
It gives me output as below.
HDR,20,Rupees
BDY,1,123
BDY,2,234
TRL,2,
But I do not want trailing comma at trailer part. Output should be as follows.
HDR,20,Rupees
BDY,1,123
BDY,2,234
TRL,2
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.