Jump to content
Changes to the Jaspersoft community edition download ×

API for managing subdatasets


Recommended Posts

By: Maikel Nait - maikelnait

API for managing subdatasets

2006-04-12 09:40

Hello. I have a webapp with a servlet that calls a report using the JasperFillManager object. This report used a java bean datasource.

 

But now, the report has a crosstab and a chart, and we use a separate subdatset for each one.

 

My question is , how to fill the report with the main dataset and the two subdatasets within the API. I can't use the JasperFillManager, as the object only accepts one datasource.

 

I have been browsing the api documentation but I can clear myself out.

 

Can anybody help me ?

 

Thanks in advance.

 

Maikel.

 

 

 

 

 

By: Rafael - rafasanmartinez

RE: API for managing subdatasets

2006-04-13 01:22

I think that I might help you, but would I need to understand a little bit better how you have structured your data sources.

 

* When you are talking about your main datasource, you describe it as a "bean datasource". Are you meaning with it that your datasource is made of a "collection of beans"?

 

* Are your sub-data sources structured the same way?

 

 

Kit :)

 

 

 

 

By: Maikel Nait - maikelnait

RE: API for managing subdatasets

2006-04-18 00:34

Yes, I'm using a "collection of beans", ( JRBeanCollectionDataSource ) on the main report datasource, and on the sub-data sources as well.

 

Any help would be really appreciated. 8-)

 

 

 

 

By: Rapsodia - rapsodia

RE: API for managing subdatasets

2006-04-20 07:06

In first time i say that i have the same problem in this moment, but in past i have used this workaround:

in JasperFillManager you pass tha datasource (for the principal report )and with parameter you pass the connection to the DB (REPORT_CONNECTION means)

After this you pass the connection to sub-report and there you do the query.

 

I don't know if you understand or if this solution is valid for your problem

 

 

 

 

By: Rafael - rafasanmartinez

RE: API for managing subdatasets

2006-04-22 03:11

I´ll try to explay how I did it to create a master-detail line subreport with an structure of beans. I am using IReport 1.2.1 for the design process.

 

The same mechanism explained here works for a detailed chart, with little variations.

 

I have not used it for cross tabs, but I guess it must be also similar.

 

1. I have one main data source, as a collection of beans. Let´s call to the bean class for this datasource "org.myorg.MainDSBean".

 

2. I have one detail subreport for each bean of the main collection. Let´s call to the bean class for the subreport datasource "org.myorg.DetailDSBean".

 

3. I have organized my datasources in the following way:

 

public class MainDSBean

{

 

private Long mainFieldA;

private String mainFieldB;

 

private List subReportLines = new ArrayList(); // !!!! I should neve leave this field null : Jasper won´t like it !!!!

 

// The property subReportLines is a list of org.myorg.DetailDSBean objects

 

...

accessors for main fields

....

 

 

public List getSubReportLines()

{

return subReportLines;

}

 

public void set getSubReportLines(List subReportLines)

{

this.subReportLines = subReportLines;

}

 

}

 

4. I create my subreport in a separate JRXML file. I call to this report "SubReport.jrxml". This report expects as it´s datasource the JRBeanCollectionDatasource, whose bean class is org.myorg.DetailDSBean, and I create my fields with their names corresponding to the org.myorg.DetailDSBean properties.

 

5. I create my main report. This report expects as it´s datasource the JRBeanCollectionDatasource whose bean class is org.myorg.MainDSBean.

 

6. In iReport, continuing with the design of my Main Report, I create a subdatasource for my detailed subreport. I call to this subdatasource "DSDetailed". In the dialog group for configuring the subdataset, I click the button "Query", then the "Javabean Datasource" tab, an enter the name of the sub dataset bean: org.myorg.DetailDSBean. The fields of the sub-report are suppose to show. I save this subdatasource. (Well..This step might not be needed for a subreport, but sure it´s needed for a chart, and does not hurt if you are doing only a sub-report).

 

7. I continue with the design of my main report, by using the subreport tool from iReports to create a new subreport: iReport will open the wizard. I click "Use an existing report" and open "SubReport.jrxml". Then, I select "Use the same connection used to fill the master report", and hit "finish".

 

8. I right click on the sub-report, and select "Properties". Then I go to the tab Subreport, and here is where the magic touch comes:

 

In "Connection/Data Source Expression", I select "Use Datasource Expression". The expression that I enter below is:

 

new JRBeanCollectionDataSource($F{subReportLines})

 

What I am doing with this, is telling to the subreport that it has to accept for datasource a collection of beans, which is the value of the field "subReportLines" of the Main Datasource. Jasper will evaulate this expression for each line of the Main Report, and that is what will produce the effect of the detailed sub-report.

 

It works perfecly for me. I hope that it will work for you.

 

Rafael

 

 

 

 

 

 

By: Maikel Nait - maikelnait

RE: API for managing subdatasets

2006-04-25 03:02

Thanks for your detailed explanations. Now I get an idea of how to solve this puzzle.

 

Muchas gracias ;-)

 

Miguel

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