Jump to content
Changes to the Jaspersoft community edition download ×

fill Report To File with two data sources


Recommended Posts

By: Trevor G - v2cib198

fill Report To File with two data sources

2003-01-12 22:46

I would like to use subreports with two or more data sources. how can I do this if the datasouce is defined at the fillReportToFile method rather then the JRLoader.loadObject method.

 

 

By: Bill Schnellinger - schnell29

RE: fill Report To File with two data sources

2003-01-16 14:41

OK.. what I think is happening here, is that the first subreport is clearing out your datasource, which you allready know.. to fix that, you need to re-set the datasource

 

but what you are realy asking is how can you pass many datasources to your many subreports

 

you can pass parameters to them with your datasource

 

you have

<subreport isUsingCache="true">

<reportElement x="10" y="0" width="100" height="15"/>

<dataSourceExpression>

$P{REPORT_DATA_SOURCE}

</dataSourceExpression>

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

$P{subreportA}

</subreportExpression>

</subreport>

 

this could be changed to

 

parameters.put("subReportDataSourceA", myCustomDataSourceForReportA);

 

and..

 

<subreport isUsingCache="true">

<reportElement x="10" y="0" width="100" height="15"/>

<dataSourceExpression>

$P{subReportDataSourceA}

</dataSourceExpression>

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

$P{subreportA}

</subreportExpression>

</subreport>

 

 

this is what Teodor was getting at

 

or you can create custome datasources, and have them created in the <dataSourceExpression> tag. ie

 

<dataSourceExpression>

new MyCustomDataSource( $F{someObjectThatHasCollections} )

</dataSourceExpression>

 

 

Hope this helps

 

Bill

 

 

By: Trevor G - v2cib198

RE: fill Report To File with two data sources

2003-01-13 03:11

No I understand how to pass a datastore I need to pass two, but if I do theres only one fill of the datastore (see example below).

 

foo.java

.

.

.

 

String fileNameA = "reportA.xml";

String reportFileA = JasperCompileManager.compileReportToFile(fileNameA);

JasperReport subreportA = (JasperReport)JRLoader.loadObject(reportFileA);

parameters.put("subreportA", subreportA);

 

String fileNameB = "reportB.xml";

String reportFileB = JasperCompileManager.compileReportToFile(fileNameB);

JasperReport subreportB = (JasperReport)JRLoader.loadObject(reportFileB);

parameters.put("subreportB", subreportB);

 

String master = "Master.xml";

String masterReportFile = JasperCompileManager.compileReportToFile(master);

String masteFilledFile = JasperFillManager.fillReportToFile(masterReportFile,parameters,<which datastore do I but in here?>);

 

 

Master.xml

.

.

.

<subreport isUsingCache="true">

<reportElement x="10" y="0" width="100" height="15"/>

<dataSourceExpression>

$P{REPORT_DATA_SOURCE}

</dataSourceExpression>

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

$P{subreportA}

</subreportExpression>

</subreport>

 

<subreport isUsingCache="true">

<reportElement x="10" y="0" width="100" height="15" />

<dataSourceExpression>

$P{REPORT_DATA_SOURCE}

</dataSourceExpression>

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

$P{subreportB}

</subreportExpression>

 

 

By: Teodor Danciu - teodord

RE: fill Report To File with two data sources

2003-07-07 12:18

 

Hi,

 

You are passing to both your subreports the data

source of the master report.

I don't think this is what you want to do.

 

I think you should pass the data source for each

subreport as parameters of the master report and

not as the data source supplied in the fillReport()

method.

 

I hope this helps.

Teodor

 

 

 

By: Teodor Danciu - teodord

RE: fill Report To File with two data sources

2003-01-13 02:46

 

Hi,

 

I'm not sure what you mean, but I guess you

are talking about a way to pass the data source

to your subreports.

 

If this is the case, then you could pass the data

source of a subreport by passing it first to the

master report and then using this parameter

in the <dataSourceExpression> of the subreport.

 

I hope this helps.

Teodor

 

 

 

By: roshansalvi - roshansalvi

RE: fill Report To File with two data sources

2005-03-31 21:32

well teodord. If i have an array of object in master datasource. then how sould i pass that array/collection as a datasource to subreport so that it can print it.

 

 

 

By: Doug Berkland - berkland

RE: fill Report To File with two data sources

2005-04-01 00:50

Assuming you have a field "Hobbies" defined in your master report and have loaded the subreport in memory and passed in as a parameter "HobbiesDetailSubreport", following will provide the hobbies as the datasource for the subreport.

 

<subreport isUsingCache="false">

<reportElement mode="Opaque" x="0" y="110" width="552" height="400" forecolor="#000000" backcolor="#FFFFFF" positionType="Float" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/>

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

<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanArrayDataSource((java.lang.Object[])$F{Hobbies})]]></dataSourceExpression>

<subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{HobbiesDetailSubreport}]]></subreportExpression>

</subreport>

.

 

 

By: pke - eklarkar

RE: fill Report To File with two data sources

2005-03-31 23:55

Hi,

I think you are trying to use same data source to fill master and sub-report...if so you can have two index variables (one for master and one for sub-report) and use if conditions to pass true or false for iterating through the data...something like this,,,

 

public boolean next() throws JRException {

if( (mainIndex == -1) || (index == -1)){

mainIndex++;

index++;

if(index < list.size()){

return true;

}else{

index = -1;

return false;

}

}

}

 

 

 

By: roshansalvi - roshansalvi

RE: fill Report To File with two data sources

2005-04-01 00:24

Well thanks for the Suggestion but the case is i am passing following instruction from my client to master report

 

JasperPrint jprint = JasperFillManager.fillReport("C://JasperTesting.jasper",para, new JRExtendedBeanDataSource(v));

 

v is Vector of Person. Person is having one method called getHobbies. Which will contain collection of Hobbies. So how should i pass it to subreport. or is there any other option to print each person hobby....

Please help me in this problem

Thanks in Advance..

Roshan

 

 

By: pke - eklarkar

RE: fill Report To File with two data sources

2005-04-01 06:15

Fill your person and hobbies data in one datasource and pass it as parameter to the main report. Use this as datasource for your filling your subreport. And print each hobby as new row of your subreport. Thats all I can say over here...

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