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
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);
HI i am new in jasper report i want to display multiple lists in my jasper report...
projectreport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 -->
<!-- 2016-09-08T15:19:00 -->
<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="projectreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a36251ec-d165-4ea4-8259-065cebd6fb88">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="projectname" class="java.lang.String"/>
<field name="contractammount" class="java.lang.Double"/>
<field name="projecttype" class="java.lang.String"/>
<field name="projectcustomer" class="java.lang.String"/>
<field name="projectdesc" class="java.lang.String"/>
<field name="startdate" class="java.lang.String"/>
<field name="start_date" class="java.util.Date"/>
<field name="enddate" class="java.util.Date"/>
<field name="completionstatus" class="java.lang.String"/>
<field name="completionstatusdate" class="java.util.Date"/>
<field name="cons_type" class="java.lang.String"/>
<field name="consdesc" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="40" splitType="Stretch">
<staticText>
<reportElement x="250" y="10" width="100" height="30" uuid="0cba4304-4afe-4705-889f-c9455a25aaf8"/>
<textElement>
<font fontName="SansSerif" size="18" isBold="true"/>
</textElement>
<text><![CDATA[Project]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="154" splitType="Stretch">
<staticText>
<reportElement x="0" y="7" width="70" height="13" uuid="b4002248-346f-4e4f-87ea-1e8c0bc20ae8"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Name]]></text>
</staticText>
<textField>
<reportElement x="90" y="10" width="100" height="20" uuid="e5612716-c6cc-4b60-a916-dec63412557c"/>
<textFieldExpression><![CDATA[$F{projectname}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="30" width="80" height="30" uuid="e90cc6b8-6e27-44b3-b9c4-189415a79faa"/>
<text><![CDATA[Total Contract Ammount]]></text>
</staticText>
<textField>
<reportElement x="90" y="30" width="100" height="20" uuid="e308a4f0-1d8f-40c7-81c2-4ca6db67be73"/>
<textFieldExpression><![CDATA[$F{contractammount}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="60" width="70" height="20" uuid="5993e836-bbcf-4925-8155-c8538139bb59"/>
<text><![CDATA[Type]]></text>
</staticText>
<textField>
<reportElement x="90" y="60" width="100" height="20" uuid="d3e5dc53-3970-4f39-8133-8face03e12f8"/>
<textFieldExpression><![CDATA[$F{projecttype}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="90" width="70" height="20" uuid="a5174c35-70ca-4ff0-acd6-8c3255e0885d"/>
<text><![CDATA[Customer]]></text>
</staticText>
<textField>
<reportElement x="90" y="90" width="100" height="20" uuid="beed5968-7eb6-4f8a-8074-b4fb3f67dd6d"/>
<textFieldExpression><![CDATA[$F{projectcustomer}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="-1" y="110" width="71" height="30" uuid="f4794615-9ded-4bc8-a172-be3b9c1f36be"/>
<text><![CDATA[Description]]></text>
</staticText>
<textField>
<reportElement x="90" y="110" width="461" height="40" uuid="95b69531-f143-45b4-ab25-0405e2ae9f52"/>
<textFieldExpression><![CDATA[$F{projectdesc}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="84" splitType="Stretch">
<line>
<reportElement x="0" y="6" width="551" height="5" uuid="a4fab58e-f047-409d-bde7-65301f9c3adf"/>
</line>
<staticText>
<reportElement x="150" y="10" width="280" height="30" uuid="1fe0e815-52cc-41a7-a66b-a34860d7cd86"/>
<textElement>
<font fontName="SansSerif" size="18" isBold="true"/>
</textElement>
<text><![CDATA[Project Construction Schedule]]></text>
</staticText>
<staticText>
<reportElement x="2" y="50" width="48" height="20" uuid="1447568d-37d6-4365-aaa6-e32a4016a746"/>
<text><![CDATA[Start Date]]></text>
</staticText>
<staticText>
<reportElement x="80" y="50" width="48" height="20" uuid="a4f661a4-a05d-4b5a-9a43-da401b703cee"/>
<text><![CDATA[End Date]]></text>
</staticText>
<staticText>
<reportElement x="400" y="50" width="48" height="20" uuid="1a832f82-0949-4de8-b18f-f4c392671227"/>
<text><![CDATA[Type]]></text>
</staticText>
<staticText>
<reportElement x="490" y="50" width="61" height="20" uuid="cbdd4c82-99b6-4562-adae-cdc0c8a49b78"/>
<text><![CDATA[Description]]></text>
</staticText>
<staticText>
<reportElement x="270" y="50" width="110" height="20" uuid="9724497b-d1de-44ad-a308-5aefb21e17e3"/>
<text><![CDATA[Completion Status Date]]></text>
</staticText>
<staticText>
<reportElement x="160" y="50" width="90" height="20" uuid="6dd565b7-2a7b-41ee-8c80-ea2135db4f6e"/>
<text><![CDATA[Completion Status]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="292" splitType="Stretch">
<textField>
<reportElement x="1" y="10" width="68" height="22" uuid="dd528090-8fa6-4bf4-aae5-7cdf9eefb9fa"/>
<textFieldExpression><![CDATA[$F{start_date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="80" y="10" width="60" height="20" uuid="68bec7f2-3e73-4d72-891b-a580e1f1db45"/>
<textFieldExpression><![CDATA[$F{enddate}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="160" y="10" width="100" height="22" uuid="336f0769-5824-4dd7-9db0-e573088b4424"/>
<textFieldExpression><![CDATA[$F{completionstatus}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="270" y="10" width="120" height="22" uuid="9713b02e-bfeb-471f-8bc1-08e2fe367b64"/>
<textFieldExpression><![CDATA[$F{completionstatusdate}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="400" y="10" width="70" height="24" uuid="56ea37e9-01f8-48b8-9a8e-8f5ddfaa9215"/>
<textFieldExpression><![CDATA[$F{cons_type}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="480" y="10" width="71" height="24" uuid="82f304c4-c248-490b-a54d-edfc9ac4d64f"/>
<textFieldExpression><![CDATA[$F{consdesc}]]></textFieldExpression>
</textField>
<line>
<reportElement x="-5" y="46" width="549" height="1" uuid="8bafef6c-96c1-42b8-a0e4-34a9d43aec37"/>
</line>
</band>
</detail>
<columnFooter>
<band height="22" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="90" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
ProductReport
public class ProductReport
{
#Autowired
BuilderProjectService builderProjectService;
public List<Map<String, ?>> allProjects()
{
int projectId = 17;
List<Map<String, ?>> listProducts = new ArrayList<Map<String,?>>();
for (BuilderProject project : builderProjectService.getProjectwithId( projectId ))
{
Map<String, Object> m = new HashMap<String, Object>();
m.put( "projectname", project.getName() );
m.put( "contractammount", project.getTotalContractAmount() );
m.put( "projecttype", project.getBuilderType().getName() );
m.put( "projectcustomer", project.getDebtorsMaster().getName() );
m.put( "projectdesc", project.getDescription() );
m.put( "consscheduleList", project.getBuilderProjectConstructionSchedules() );
listProducts.add( m );
}
return listProducts;
}
}
Controller
#RequestMapping(value = "/report", method = GET)
public String reportjsp(ModelMap modelMap) throws IOException {
modelMap.put( "listProducts", productReport.allProjects() );
return "report";
}
Report JSP
<%# page contentType="application/pdf"%>
<%# page trimDirectiveWhitespaces="true"%>
<%# page import="net.sf.jasperreports.engine.*"%>
<%# page import="net.sf.jasperreports.engine.data.*"%>
<%# page import="java.io.*"%>
<%# page import="java.util.*"%>
<%
try {
List<Map<String, ?>> datasource = (List<Map<String, ?>>) request.getAttribute( "listProducts" );
JRDataSource jrDataSource = new JRBeanCollectionDataSource(datasource);
String jrxmlFile = session.getServletContext().getRealPath("/reports/projectreport.jrxml");
InputStream input = new FileInputStream(new File(jrxmlFile));
//Generating the report
JasperReport jasperReport = JasperCompileManager.compileReport(input);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jrDataSource);
//Exporting the report as a PDF
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
}
catch (Exception e)
{
System.out.println("Exception in PDF Report Printing");
/* e.printStackTrace( ); */
}
%>
Now my problem is in Product Report i sending a list and i want to print it under project construction schedule how to do this ?
the problem is also describe in image
Iam trying to call procedure from jasper reports but I'm getting this error
sf.jasperreports.engine.JRException: Error executing SQL statement for : ReportTemplate
Although procedure is working fine in when I'm calling it from mysql. This is the way i hve call procedure from JasperReports
<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="ReportTemplate" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c01724b6-8aeb-4f3e-9c46-00fab3c0b602">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="param1" class="java.lang.String"/>
<queryString>
<![CDATA[Call Student_fee_report ($P{param1})]]>
</queryString>
<field name="FeeType" class="java.lang.String"/>
<field name="Fee_Head_Name" class="java.lang.String"/>
<field name="Amount" class="java.lang.String"/>
<field name="Expected_Month_Year" class="java.lang.String"/>
<field name="sub" class="java.lang.String"/>
<field name="Status" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="56" splitType="Stretch">
<staticText>
<reportElement uuid="aed283f1-6b6d-4eb4-94df-7ce177ff85d1" x="0" y="0" width="600" height="46"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="22" isBold="true"/>
</textElement>
<text><![CDATA[Student Fee Detail]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="13" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="25" splitType="Stretch">
<staticText>
<reportElement uuid="71f2d5cb-dcfa-46fc-ab1f-a1c07eb7a8f2" x="50" y="0" width="90" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Fee Type]]></text>
</staticText>
<staticText>
<reportElement uuid="975fc716-7a73-493b-ad25-9bd16650fb8a" x="140" y="0" width="90" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Fee Name]]></text>
</staticText>
<staticText>
<reportElement uuid="2dd37133-d509-4b77-a40c-ec62a180862c" x="230" y="0" width="100" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement uuid="0ed8adcd-6b05-4212-aff1-a4f8528aa301" x="330" y="0" width="110" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Expected Date]]></text>
</staticText>
<staticText>
<reportElement uuid="314552a3-3e73-454d-acbc-8b6f186f997a" x="440" y="0" width="110" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Submission Date]]></text>
</staticText>
<staticText>
<reportElement uuid="b1d93a9a-3f19-4eba-a877-a4ccc64f2e90" x="10" y="0" width="27" height="20"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Status]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="25" splitType="Stretch">
<textField>
<reportElement uuid="4ee795b7-b55b-470d-ba6d-3679dc631f3c" x="50" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{FeeType}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="ae6209b5-5211-4ec4-bbc6-493260acb2f3" x="140" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Fee_Head_Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="5df479c0-c886-44ac-9f38-8e29558b3cff" x="230" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="82c52ca4-63de-43c4-9117-f20de45e0615" x="330" y="0" width="110" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Expected_Month_Year}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="e78448c2-b25e-4351-b078-56c62aa43570" x="440" y="0" width="110" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{sub}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="52b24bc7-382c-4408-b957-6d6dd1fea00c" x="10" y="0" width="27" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Status}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="23" splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
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.