I'm new to Jaspersoft and all the articles I've read about using javabeans as datasource for reports with subreports are not working. The main report has data shown but the subreport is blank even if the datasource is not empty and/or AllSectionsNoDetail is selected.
I've tried passing the subreport data as param and as field. Both approaches didnt work. It would always say, "WARN JRJdbcQueryExecuter:129 - The supplied java.sql.Connection object is null."
...
....
package com.cmsbeta.web.function.reportfilter.page;
import java.util.ArrayList;
...
public class ChargeTypeListReportFilterPage extends CptiBasePage {
@SpringBean
private ChargeTypeService chargeTypeService;
@SpringBean
private EntryService entryService;
private String searchCode;
private String searchDescription;
private Boolean searchIncludeInactive;
public ChargeTypeListReportFilterPage() {
setPageTitle("report.title.chargetypelist");
TextField<String> code = new TextField<String>("code", new PropertyModel<String>(this, "searchCode"));
TextField<String> description = new TextField<String>("description", new PropertyModel<String>(this, "searchDescription"));
CheckBox includeInactive = new CheckBox("includeInactive", new PropertyModel<Boolean>(this, "searchIncludeInactive"));
Form<?> form = new Form<Void>("form");
form.add(new AttributeAppender("target", Model.of("_blank")));
SubmitLink submit = new SubmitLink("submit") {
@Override
public void onSubmit() {
List<ChargeType> chargeTypes = chargeTypeService.search(searchCode, searchDescription, null, searchIncludeInactive);
List<ChargeTypeAndEntries> data = new ArrayList<ChargeTypeAndEntries>();
for(ChargeType chargeType : chargeTypes){
ChargeTypeAndEntries cae = new ChargeTypeAndEntries();
cae.setId(chargeType.getId());
cae.setAmount(chargeType.getAmount());
cae.setCode(chargeType.getCode());
cae.setCreateDate(chargeType.getCreateDate());
cae.setCreatedBy(chargeType.getCreatedBy());
cae.setDescription(chargeType.getDescription());
cae.setIsSpecial(chargeType.getIsSpecial());
cae.setStatus(chargeType.getStatus());
cae.setVatComputation(chargeType.getVatComputation());
cae.setEntries(entryService.findBySource(CmsConstants.CHARGE_TYPE_SOURCE , chargeType.getId()));
data.add(cae);
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("Title", getString("report.title.chargetypelist"));
List<KeyValuePair> subreportKvp = new ArrayList<KeyValuePair>();
subreportKvp.add(new KeyValuePair(0, "charge_type_entries.jrxml"));
try {
CmsUtil.showJasperReport(getRequestCycle(), data, "charge_type_list.jrxml", param, subreportKvp);
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
add(form);
form.add(code);
form.add(description);
form.add(includeInactive);
form.add(submit);
}
}
public static void showJasperReport(RequestCycle requestCycle, List<?> data, String jrxmlFileName, Map parameters, List<KeyValuePair> subreports) throws JRException {
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(data);
//Create an instance of JasperReport of the subreport then pass that instance to the main report as a parameter
InputStream jrxmlUrl = CmsJasperReportsResource.class.getResourceAsStream(jrxmlFileName);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); //produces a .jasper file when compiled using ANT
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource); //produces a jrprint file when compiled using ANT
requestCycle.scheduleRequestHandlerAfterCurrent(new ResourceRequestHandler(jr, null));
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.3.final using JasperReports Library version 6.0.3 -->
<!-- 2015-07-03T18:15:40 -->
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="TitleSubreport" class="net.sf.jasperreports.engine.JasperReport"/>
<parameter name="Logo" class="java.lang.String"/>
<parameter name="Title" class="java.lang.String"/>
<parameter name="0" class="net.sf.jasperreports.engine.JasperReport"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="code" class="java.lang.String">
<fieldDescription><![CDATA[code]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="status" class="java.lang.Integer">
<fieldDescription><![CDATA[status]]></fieldDescription>
</field>
<field name="entries" class="java.util.List">
<fieldDescription><![CDATA[entries]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="111" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<subreport>
<reportElement x="0" y="0" width="555" height="75" uuid="a7e88471-87ab-4fde-af5c-dd9efb3ba01d">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<subreportParameter name="Logo">
<subreportParameterExpression><![CDATA[$P{Logo}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{TitleSubreport}]]></subreportExpression>
</subreport>
<textField>
<reportElement x="0" y="80" width="555" height="30" uuid="77214317-16c6-4274-ba47-a6894e398e7c">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Center">
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{Title}]]></textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement mode="Transparent" x="0" y="0" width="110" height="20" backcolor="#80FFFF" uuid="8c18596e-045e-461d-ab0a-ea1a31aec7be">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Code"]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Transparent" x="110" y="0" width="370" height="20" backcolor="#80FFFF" uuid="599bd22c-bbb7-4397-b926-c8c17456fcfc">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Description"]]></textFieldExpression>
</textField>
<rectangle>
<reportElement mode="Transparent" x="0" y="-1" width="555" height="20" uuid="d302a302-e5ae-4c65-868f-e5e8497932f7"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</rectangle>
<textField>
<reportElement mode="Transparent" x="445" y="0" width="110" height="20" backcolor="#80FFFF" uuid="10093ca2-491a-4db5-838f-44faebe163a5">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Status"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="83" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement x="0" y="0" width="110" height="15" uuid="2a7e1f46-89ee-4276-95b5-c54c85b9fa6e">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{code}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="110" y="0" width="334" height="16" uuid="c9f46d33-da4e-44a5-b6fc-cc5e12b16611">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="445" y="0" width="110" height="15" uuid="e7b1b8a3-d7bc-432d-b486-11b3daa53087">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{status} == 1 ? "Active" : "Inactive"]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="0" y="16" width="555" height="54" uuid="ae8044f8-7102-4fac-8d74-32269b39f994"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{entries})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{0}]]></subreportExpression>
</subreport>
</band>
</detail>
<pageFooter>
<band height="15" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement x="485" y="0" width="70" height="15" uuid="2e1789d0-d635-468d-8c6f-9d4da77c0c36">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<line direction="BottomUp">
<reportElement x="0" y="0" width="555" height="1" uuid="9392f64f-f2d5-4416-9b38-586bf4754089">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
</band>
</pageFooter>
<summary>
<band height="42" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</band>
</summary>
</jasperReport>
Subreport:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.3.final using JasperReports Library version 6.0.3 -->
<!-- 2015-07-03T18:15:38 -->
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="amount" class="java.math.BigDecimal">
<fieldDescription><![CDATA[amount]]></fieldDescription>
</field>
<field name="description" class="com.cmsbeta.hibernate.domain.EntryType">
<fieldDescription><![CDATA[entryType.description]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="57" splitType="Stretch">
<staticText>
<reportElement x="0" y="39" width="500" height="18" uuid="90bcd75e-481e-42f5-a187-4896b1e9578e"/>
<textElement>
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Entry Description]]></text>
</staticText>
<staticText>
<reportElement x="500" y="39" width="95" height="18" uuid="ff86ec03-5cd8-4983-a8c1-afd6d11e7dae">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement>
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="0" y="4" width="595" height="30" uuid="de23d538-747a-4021-a8ed-7b744ba9beb3"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<text><![CDATA[List of Entries]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="28" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="500" height="20" uuid="4fe8bf65-eb79-4bfc-8474-3883c371f184"/>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="500" y="0" width="95" height="20" uuid="3d70aa01-bb72-4226-b672-17a01821891e"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
just kindly show me in detail how to use java beans as datasource. could be like one datasource per subreport. thanks a lot