Jump to content
Changes to the Jaspersoft community edition download ×

Report with subreport with sub-subreport


2004 IR Help

Recommended Posts

By: dawuad - dawuad

Report with subreport with sub-subreport

2005-06-03 10:24

We have the following structure:

Frame

-> Flights

->FlightSegments

 

Frame is the Main Report which contains Flights subreport. Flights subreport contains several flight segments subreports. Flightsegments needs a datasource. The following is our sourcecode:

 

Code:
//Frame  
File framefile = new File(context.getRealPath("/jasper/reports/frame.jasper"«»));
JasperReport framejr = (JasperReport) JRLoader.loadObject(framefile);

//Flights
File flightsfile = new File(context.getRealPath("/jasper/reports/flight/flights.jasper"«»));
JasperReport flightsjr = (JasperReport) JRLoader.loadObject(flightsfile);
Map flightparameters = new HashMap();
List<FlightSegments> inboundlist = new ArrayList<FlightSegments>();
List<FlightSegments> outboundlist = new ArrayList<FlightSegments>();
List<FlightSegments> internallist = new ArrayList<FlightSegments>();

String outboundexist = "false";
String inboundexist = "false";
String internalexist = "false";

Hashtable hash = bbean.getFlightReport(group.getBookingID().getId());
outboundlist = (List<FlightSegments>«»)hash.get("list1"«»);
inboundlist = (List<FlightSegments>«»)hash.get("list2"«»);
internallist = (List<FlightSegments>«»)hash.get("list3"«»);

JRBeanCollectionDataSource outboundds = new JRBeanCollectionDataSource((Collection)outboundlist);
JRBeanCollectionDataSource inboundds = new JRBeanCollectionDataSource((Collection)inboundlist);
JRBeanCollectionDataSource internalds = new JRBeanCollectionDataSource(internallist);

if(outboundlist != null && !outboundlist.isEmpty())
outboundexist="true";
if(inboundlist != null && !inboundlist.isEmpty())
inboundexist="true";
if(internallist != null && !internallist.isEmpty())
internalexist="true";

//Flightsegments
File flightssegmentssub = new File(context.getRealPath("/jasper/reports/flight/flightsegments.jasper"«»));
JasperReport flightsegmentsubreport = (JasperReport)JRLoader.loadObject(flightssegmentssub);

flightparameters.put("flightsegment", flightsegmentsubreport);
flightparameters.put("outboundexist", outboundexist);
flightparameters.put("inboundexist", inboundexist);
flightparameters.put("internalexist", internalexist);

flightparameters.put("outboundds", outboundds);
flightparameters.put("inboundds", inboundds);
flightparameters.put("internalds", internalds);
JasperFillManager.fillReport(flightsjr, flightparameters, new JREmptyDataSource());

Map frameparameters = new HashMap();
frameparameters.put("Flights", flightsjr);

frameparameters.put("flightsegment", flightsegmentsubreport);
frameparameters.put("outboundexist", outboundexist);
frameparameters.put("inboundexist", inboundexist);
frameparameters.put("internalexist", internalexist);

frameparameters.put("outboundds", outboundds);
frameparameters.put("inboundds", inboundds);
frameparameters.put("internalds", internalds);

jp = JasperFillManager.fillReport(framejr, frameparameters, new JREmptyDataSource());

 

We thought this would work, but it does not. Can anyone point out how we can make this type of report work!

 

 

 

 

By: C-Box - c-box

RE: Report with subreport with sub-subreport

2005-06-03 12:16

Complex but feasible (IMHO)...

 

Just what I'd suggest..(not coded.... just from mind after a hard week of work).

 

First... just call the fillmethod ONCE --> with the masterdatasource ( I guess "outboundds"--> the datasource for the masterreport) Also prepare just one parametermap....

 

put ALL parameter inside this map (even if the parameter are used within the nested subreport)...so put all datasources and all subreports also into that parametermap.

 

So you finally call just once the fillmethod - for example:

 

jp = JasperFillManager.fillReport(framejr, allparameters, outboundds);

 

In your SubReport-Expression you use the Parameter like this: $P{Flights}..... for the datasource-expressions you use also the corresponding parameter: $P{inboundds}... and pass the REPORT_PARAMETER_MAP from one report to the next (sub)report....

 

So you can nest several levels.

 

I also do it a bit different but nevertheless a bit similiar.

 

hth

C-Box

 

 

 

 

By: Manfred Moser - mosabua

RE: Report with subreport with sub-subreport

2005-08-11 15:19

I have been using this kind of approach for a while and it does work. Just in case you are wondering...

 

manfred

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