Jump to content
Changes to the Jaspersoft community edition download ×

Subreport not displaying JavaClass Datasource


2005 IR Help

Recommended Posts

By: Jeff - logicacmg

Subreport not displaying JavaClass Datasource

2004-04-28 09:41

Subreports not displaying with, Java Class Datasource

 

I am trying to get subreports working, passing the values in from a JavaClass (Code samples below). Both the Master and Subreport correctly display the returned data by themselves, but I am unable to get the subreport to actually appear in the Master report.

 

Can anyone help show me what I am doing wrong. I have been through the samples supplied with JasperReports, but am unable to find what I've got wrong. I would be willing to purchase the documentation if I could be assured that doing so would actually be of benifit in this instance.

 

I assume that somewhere in the passing of the subreport into the main report is where the problem is, but I've spent hours trying various things and have not made any headway.

 

All help is greatly appreciated.

Jeff.

 

 

********* The Java Class where I populate the reports and export them out to PDF **************

 

// Populate the Sub Report - Activity

subParam.put("labelName", new String("Name") );

subParam.put("labelDescription", new String("Description") );

Subreport_ActivityCollection subAct = new Subreport_ActivityCollection();

 

// Get the JasperReport object (for the Activity Subreport)

JasperReport jasperSubActivityReport = (JasperReport) cm.getAttribute("JASPER_SUB_ACTIVITY_REPORT");

 

// Fill the report and get the JasperPrint object

JasperPrint subAct = JasperFillManager.fillReport(jasperSubActivityReport, subParam, new JRBeanArrayDataSource(subAct.getActivityArray()));

 

// Just for TESTING purposes export the Subreport to a pdf file

JasperExportManager.exportReportToPdfFile(subAct, "Sub_Activity_Report.pdf");

 

// Pass the Populated Subreport to the Main report.

parameters.put("activitySubReport", jasperSubActivityReport ); // Pass in the SubReport

 

// Get the Main report

JasperReport jasperReport = (JasperReport) cm.getAttribute("JASPER_REPORT");

 

// Create JasperPrint using fillReport() method

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, mainDao.DBConnection);

 

// Export to PDF

JasperManager.printReportToPdfFile(jasperPrint, "Report.pdf");

 

 

************** The Master Report XML (Segment that I think is of interest) ***********

<jasperReport columnWidth="555"

name="EUETS_Report"

pageHeight="842"

pageWidth="595"

orientation="Portrait"

leftMargin="20"

topMargin="30"

printOrder="Vertical"

columnCount="1"

whenNoDataType="NoPages">

 

 

<parameter name="activitySubReport" class="dori.jasper.engine.JasperReport"/>

 

<detail>

<band height="600" isSplitAllowed="true">

<rectangle radius="0">

<reportElement x="0" y="4" width="555" height="590"/>

</rectangle>

<subreport isUsingCache="true" >

<reportElement x="50" y="290" width="325" height="160" backcolor="#FFCC99" isPrintRepeatedValues="true" isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="false"/>

{NOTE:This bit is <!--<subreportExpression class="dori.jasper.engine.JasperReport">

$P{activitySubReport}

Commented Out} </subreportExpression>-->

<subreportParameter name="activitySubReport">

<subreportParameterExpression>$P{activitySubReport}</subreportParameterExpression>

</subreportParameter>

<dataSourceExpression>$P{activitySubReport}</dataSourceExpression>

</subreport>

</band>

 

</detail>

 

 

 

*************** The Subreport XML ********************************

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="classic"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="480"

pageHeight="150"

columnWidth="340"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<reportFont name="Arial_Normal" fontName="Arial" size="8" isPdfEmbedded="false" pdfEncoding="CP1252" pdfFontName="Helvetica" isStrikeThrough="false" isUnderline="false" isItalic="false" isBold="false" isDefault="true"/>

<reportFont name="Arial_Bold" fontName="Arial" size="8" isPdfEmbedded="false" pdfEncoding="CP1252" pdfFontName="Helvetica-Bold" isStrikeThrough="false" isUnderline="false" isItalic="false" isBold="true" isDefault="false"/>

 

<!-- Report Values -->

 

<!-- Report Labels -->

<parameter name="labelName" class="java.lang.String"/>

<parameter name="labelDescription" class="java.lang.String"/>

<!-- Report Fields -->

<field name="name" class="java.lang.String"/>

<field name="description" class="java.lang.String"/>

 

<columnHeader>

<band height="20" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement mode="Transparent" x="1" y="0" width="160" height="15" forecolor="#000000"

backcolor="#FFFFFF" positionType="Float" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single">

<font fontName="" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$P{labelName}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement mode="Transparent" x="160" y="0" width="160" height="15" forecolor="#000000"

backcolor="#FFFFFF" positionType="Float" isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single">

<font fontName="" pdfFontName="Helvetica" size="12" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="CP1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$P{labelDescription}]]></textFieldExpression>

</textField>

</band>

</columnHeader>

<detail>

<band height="18" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement mode="Transparent" x="1" y="5" width="160" height="13" forecolor="#000000"

backcolor="#FFFFFF" positionType="Float" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"></textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement mode="Transparent" x="160" y="5" width="362" height="13" forecolor="#000000"

backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"></textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{description}]]></textFieldExpression>

</textField>

</band>

</detail>

</jasperReport>

 

 

 

 

 

By: Jeff - logicacmg

RE: Subreport not displaying JavaClass Datasource

2004-04-28 17:25

Can no one help with this? I've been through every subreport question posted on this discussion and tried tried any suggestions there, no luck. I still do not see the subreport displayed in the main report. What am I doing wrong?

 

Jeff.

 

 

 

 

By: Jeff - logicacmg

RE: Subreport not displaying JavaClass Datasource

2004-04-28 22:35

Can someone at least tell me if these few lines are correct, are they actually passing the populated report to the main report?

 

// Fill the report and get the JasperPrint object

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperActivityReport, subActParam, new JRBeanArrayDataSource(ActivityCollection.getActivityArray()));

 

// Just for TESTING purposes export the Subreport to a pdf file

JasperExportManager.exportReportToPdfFile(jasperPrint, "Activity_Report.pdf");

 

// Pass the Populated Subreport to the Main report.

parameters.put("activitySubReport", jasperActivityReport ); // Pass in the SubReport

 

 

 

 

By: C-Box - c-box

RE: Subreport not displaying JavaClass Datasource

2004-04-28 22:36

I don't know if it is necessary to fill the SubReport first...

 

I did it that way:

 

1.) Load SubReport and MainReport

2.) Compile both reports

3.) Fill SubReport's CustomDatasource

4.) Put parameters to HashMap (including SubReport's CustomDataSource)

5.) Fill MasterReport with it's Connection or it's own CustomDataSource or JREmptyDatasource

6.) Show the returned JasperPrint-Object

 

Don't try passing the datasource by single parameter in the MasterReport.xml's SubReportSection... I also got mad with that, but I have 4 different datasources that I first passed with each single variable into subreport... it did not work like I wanted.

 

But when I put the:

<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]><parametersMapExpression>

 

into my SubReport-Section I got at least some data from SubReport

(but not filtered to the parameter that I also pass to SubReport and should just show SubReportData that match with that parameter and not ALL --> but that's another topic I also posted here.)

 

I also don't know if you need the

<dataSourceExpression>$P{activitySubReport}</dataSourceExpression>

 

in your MasterReport's XML ....instead try to pass your DataSource into MasterReport using Parameter (e.g. <parameter name="MyCustomBeanDataSourceForSubReport" class="dori.jasper.engine.JRDataSource"/>)

and then try to put the

<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]><parametersMapExpression>

to the SubReport

 

 

hth

C-Box

 

 

 

 

 

By: Jeff - logicacmg

RE: Subreport not displaying JavaClass Datasource

2004-04-28 23:09

OK, I tried that, no difference. Can I just confirm what the subreport section of the master report shoudl look like.

 

<subreport isUsingCache="true" >

<reportElement x="5" y="200" width="400" height="160" backcolor="#FFCC99" isPrintRepeatedValues="true" isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="false"/>

<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]>

</parametersMapExpression>

</subreport>

 

Also, do I need to have REPORT_PARAMETERS_MAP (I assume I am meant to type this in as is, and not replace it with something else?) specified anywhere in the actual subreport?

 

Thanks for your help so far.

 

 

 

 

By: C-Box - c-box

RE: Subreport not displaying JavaClass Datasource

2004-04-28 23:31

You need the SubReportExpression yet.

 

look here what I've posted with SubReport:

http://sourceforge.net/forum/forum.php?thread_id=1066582&forum_id=113530

 

your SubReportSection of MasterReport should be:

<subreport isUsingCache="true" >

<reportElement x="5" y="200" width="400" height="160" backcolor="#FFCC99" isPrintRepeatedValues="true" isPrintWhenDetailOverflows="true" isRemoveLineWhenBlank="false"/>

<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]>

</parametersMapExpression>

<subreportExpression class="dori.jasper.engine.JasperReport">

$P{activitySubReport}

</subreportExpression>

</subreport>

 

The "REPORT_PARAMETERS_MAP" is a JasperReport BuiltInVariable (so I've read in that forum) you needn't replace it with other string.

 

But you should have the same parameter in you SubReport.xml

 

So just read the link above, I hope it helps you.

 

C-Box

 

 

 

 

 

 

By: Jeff - logicacmg

RE: Subreport not displaying JavaClass Datasource

2004-04-29 00:25

(I don't think my last post got through)

 

No luck. The exact same thing happens. The main report is generated ok, except for the subreport, it is not displayed.

 

I have also tried with following the code in the link you provided, the same thing, no subreport.

 

Surely it is not that hard to generate a report with a subreport using a JavaClass as the datasource. I must be missing something basic.

 

I will be back in the morning.

 

Thanks for the help, any other suggestions? Would the JasperReports ebook be of any help in this case?

 

Thanks,

Jeff.

 

 

 

 

By: Jeff - logicacmg

RE: Subreport not displaying JavaClass Dataso

2004-05-01 19:31

FINALLY figured it out.

 

Apparently the defult setting for the subreport reportElement mode is Transparent. When I explicitly added mode="Opaque" it all appeared and is working correctly. So obviously it WAS working correctly, just was set to invisible.

 

Thanks C-Box for all your help.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...