Jump to content
We've recently updated our Privacy Statement, available here ×

dynamic report of 1 to 12 different sections


ktrinad

Recommended Posts

By: Andrew Arrow - andrewarrow

dynamic report of 1 to 12 different sections

2002-06-10 16:16

Hello,

 

I need to generate a dynamic pdf report of 1 to 12 different sections. The User is given a choice of including or not including each of the 12 sections and the user gets to pick the order. For example, they could have:

 

Section 1

Section 2

Section 3

 

And get a 3 section report. Or they might pick:

 

Section 8

Section 5

Section 1

Section 9

Section 12

 

And have a 5 section report, in a non-sequential order.

 

Each section should start on a new page. Some sections are very complex reports with many columns iterating over a large dataset. Some sections are very simple 1 page reports with mostly static text. Each section needs to start on a new page. What's the best way to structure this... Should I have one master report with 12 sub-reports and I dynamically generate this xml file at runtime with the sections in the correct order?

 

Is there a way to specify the order and which sections are to be included without dynamically writing the xml file? If I am using 12 sub-reports, where should they go? In the title section of the master report or in the detail section? What's the report section width and height for the sub-reports? How can I know this?

 

Thanks!

 

-Andrew

 

 

By: Teodor Danciu - teodord

RE: dynamic report of 1 to 12 different sections

2002-06-11 01:02

 

Hi,

 

Here's what I would do:

 

Create a special data source that has only one

field representing the ID of the section.

If you want to create a report with only 5 sections,

the data source of your master report will have 5 rows.

For each of them, it will provide the ID of the section

using the master report defined field, as I said.

 

Yes, we shall use 12 subreports.

 

But before that, in the master report, we should

create a dummy group that will have as group

expression the field that contains the section ID.

This way, a new group will be started for each of the

5 rows in the master report, allowing us to use the

"isStartNewPage" attribute, in order to start a new

page for each section.

 

In the detail section of the master report we shall

put all the 12 subreports, one on top of the other,

but we shall make use of the "printWhenExpression"

to indicate that, for example, the subreport

corresponding to the section number 8 should print

only when the section ID field of the master report is 8.

 

That should be it. Finally, the Connection object

should be sent as parameter in the master report

in order to be passed to the subreports.

 

Good luck!

Teodor

 

 

 

By: Andrew Arrow - andrewarrow

RE: dynamic report of 1 to 12 different sections

2002-06-12 16:33

Okay here's what I got so far. Trouble is whenever I include more than 1 subreport I get a Null Pointer Exception at dori.jasper.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:315)

 

Do I have the printWhenExpression done correctly?

 

<jasperReport

name="Master"

pageWidth="612"

pageHeight="792"

leftMargin="20"

rightMargin="20"

topMargin="30"

bottomMargin="30"

isTitleNewPage="false"

isSummaryNewPage="false">

 

<parameter name="RSD" class="dori.jasper.engine.JRDataSource"/>

<field name="Id" class="java.lang.Integer"/>

 

<group name="DummyGroup" isStartNewPage="true" isStartNewColumn="true" isResetPageNumber="false" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="200">

<groupExpression>

$F{Id}

</groupExpression>

<groupHeader>

<band height="0"/>

</groupHeader>

<groupFooter>

<band height="0"/>

</groupFooter>

</group>

 

<title>

<band height="0"/>

</title>

 

 

<pageHeader>

<band height="0"/>

</pageHeader>

 

<columnHeader>

<band height="0"/>

</columnHeader>

 

<detail>

<band height="50">

 

 

<subreport isUsingCache="false">

 

<reportElement x="5" y="5" width="50" height="50">

<printWhenExpression>new Boolean($F{Id}.intValue() == 1)</printWhenExpression>

</reportElement>

 

<dataSourceExpression>

$P{RSD}

</dataSourceExpression>

 

<subreportExpression class="java.lang.String">

"TableOfContents.jasper"

</subreportExpression>

 

</subreport>

 

 

<subreport isUsingCache="false">

 

<reportElement x="5" y="5" width="50" height="50">

<printWhenExpression>new Boolean($F{Id}.intValue() == 2)</printWhenExpression>

</reportElement>

 

<dataSourceExpression>

$P{RSD}

</dataSourceExpression>

 

<subreportExpression class="java.lang.String">

"CloseOut.jasper"

</subreportExpression>

 

</subreport>

 

</band>

</detail>

 

<columnFooter>

<band height="0"/>

</columnFooter>

 

<pageFooter>

<band height="0"/>

</pageFooter>

 

<summary>

<band height="0"/>

</summary>

 

</jasperReport>

 

 

 

By: Teodor Danciu - teodord

RE: dynamic report of 1 to 12 different sections

2002-06-13 04:35

 

Hi,

 

There is indeed a bug in the JRFillSubreport class.

 

I'll post a patched version of this class in the Patches section at sourceforge.net.

 

Thank you,

Teodor

 

 

 

By: Andrew Arrow - andrewarrow

patch error

2002-06-13 09:17

I get:

 

compile:

[javac] Compiling 201 source files to C:cvsprojectsBMGexternalJasperReportsclasses

[javac] C:cvsprojectsBMGexternalJasperReportssrcdorijasperenginefillJRFillSubreport.java:96: cannot resolve symbol

[javac] symbol : method getParametersMapExpression ()

[javac] location: interface dori.jasper.engine.JRSubreport

[javac] return ((JRSubreport)this.parent).getParametersMapExpression();

[javac] ^

[javac] 1 error

 

BUILD FAILED

 

 

 

By: Andrew Arrow - andrewarrow

error

2002-06-13 18:30

Sorry, ignore that last compiler error, my classpath fault. The null pointer exception is gone, and I now get X # of pages, 1 for each of the sections... but only 1 sub-report will show. The rest of the pages are blank. Any ideas?

 

<detail>

<band height="20">

<subreport isUsingCache="true">

 

<reportElement x="5" y="5" width="50" height="500">

<printWhenExpression>new Boolean($F{Id}.intValue() == 1)</printWhenExpression>

</reportElement>

 

<dataSourceExpression>

$P{RSD}

</dataSourceExpression>

 

<subreportExpression class="java.lang.String">

"TableOfContents.jasper"

</subreportExpression>

 

</subreport>

 

<subreport isUsingCache="true">

 

<reportElement x="5" y="5" width="50" height="500">

<printWhenExpression>new Boolean($F{Id}.intValue() == 2)</printWhenExpression>

</reportElement>

 

<dataSourceExpression>

$P{RSD}

</dataSourceExpression>

 

<subreportExpression class="java.lang.String">

"CloseOut.jasper"

</subreportExpression>

 

</subreport>

</band>

</detail>

 

 

By: Teodor Danciu - teodord

RE: error

2002-06-13 23:56

 

Hi,

 

I suspect only the first subreport is printed because

you pass the same data source to all your subreports.

 

After the first subreport, the pointer in your data

source reaches the last row and remains there,

so to the next subreport the data source appears

to be empty.

 

If it is a custom data source, add a moveFirst()

method to it that will reposition the cursor before

the first row and call it, or always pass a new data

source to each subreport.

If your data source does not really contain data,

but only creates records, you might find the

JREmptyDataSource() useful.

 

Good luck!

Teodor

 

 

 

By: Emiliano Heyns - emiliano

RE: dynamic report of 1 to 12 different secti

2004-04-10 12:05

How do I pass a new DataSource to a new subreport?

 

 

By: Jan Dieckmann - jandieck

RE: dynamic report of 1 to 12 different sections

2004-04-16 07:12

May be you could solve the problem using the java api. The decorator pattern could help. The main report contains some part which are common to all selections. The user could choose some of the 1..12 sections and you decorate your main report with the selected sections. Please read my posting on 2004-03-30 ("To xml or not to xml").

 

regards Jan

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...