JasperReports: unrecoverable multipage subreports - jasper-reports

For example i have Master report that contains several multipage subreports. I want them to be displayed in order that is set in master report (prints the first subreport and then prints second). When i add these subreports into master datail band, they cover each other.
How can i do such thing?
Thank you

Have you tried putting each subreport in its own detail band? Or, if you're putting the subs in an array, include another variable like "reportName" or "reportNumber" and group the subreport detail bands by that variable, so each time the variable changes a new group is created for the new subreport. Doing it that way would also let you put a group header for each subreport which you could then customize with variables and/parameters. Just a thought.

I found the satisfied solution:
i fill all my reports separately, but export them by JRPdfExporter:
List jasList = new ArrayList();
jasList.add(jp_1);
jasList.add(jp_2);
jasList.add(jp_3);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "batch.pdf");
exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
exporter.exportReport();
They will be ordered in list order and bookmarks will be generated

Related

Printing the head line only on first page

I have jasper report which is created by many objects.
I want the header in one object. The object may come any where in the report.
How can i print header only on the first page of the object.
Can i use print when expression if page number equals 1.
is that page no means for whole pdf report or for only single jrxml object.
Thanks.
What does you mean anywhere in the report? If you want to print a title only once and in the first page, use the Title band in the jasper reports. No need of additional conditions required.

How does one dynamically take values from a Group, add it to an Array, and then print individual values in the Page Footer?

I have a report file, where the report provides information on a "Job" - so this is a "Job Ticket" report. Inside the Job Ticket, there is a group with details that provides information on individual "Components" of which there can be anywhere from 1 Component to 6 Components in any given Job. There is a field applied to each component which is a string and is the "ComponentType" ({sp_JobTicket.ComponentType}).
What I would like to do is put the value of each row of ComponentType into an Array, which I can then call in the Page Footer (i.e., so I can create a Text Object and in it call a value using something like "TypeforComponent[3]"), so even though every printed page will only show the full details of one component, the page footer for each page will provide an at-a-glance view of all the components and their types.
As it is right now, we just hand write the component types for all components on the printed page itself, but we can access the ComponentType through the database, so it seems like we should be able to get it to print on the report.
Here is a full page preview of of a printed Job Ticket report that has 4 components (so in the Page Footer only 1-4 would have a value, 5-6 are empty), and where everything is currently laid out, and where we're hoping to get things placed:
Lots of questions but assuming this report is run for only 1 job ticket at a time here is one possibility:
Create formula called CT_Array and place in header1 section and suppress:
WhileReadingRecords;
stringvar array CT_Array ;
stringvar output := "";
numbervar i := ubound(CT_Array)+1;
redim preserve CT_Array[i];
CT_Array[i] := {sp_JobTicket.ComponentType};
Then create 6 formulas (CT_Var1 through CT_Var6) to read as follows:
WhileReadingRecords;
stringvar array CT_Array ;
CT_Array[1]
Replacing CT_Array[1] with the next array element number
Place those formulas where needed in page footer.
CT_Var2
WhileReadingRecords; stringvar array CT_Array ;
if ubound(CT_Array) >
1 then CT_Array[2] else ""
etc... for CT_Var3 through 6
So it looks like the simpler and more straight-forward solution to my problem was to not use an Array, but to create a Subreport.
I accomplished this by creating a new report, linked it to the stored procedure used by my Job Ticket (main) report, and imported the data fields I needed. I then proceeded to change the Page Size for the subreport to fit into the size on the page (1.5" x 1"), set the Details section to "Format with Multiple Columns" in the section expert which made available a new "Layout Tab" which I entered and selected "Format Groups with multiple column[s]." Then I saved that as a separate file and imported that report into my main report as a Subreport. Finally I set the Subreport Links to link to my "JobNumber" field which my main ticket uses as a parameter and that Field to the parameter.
Completed Successfully:

dynamicjasper addConcatenatedReport in a frame

Is it possible to concatenate subReports in a frame placed in the detail band? The goal is to display these subReports and the previous defined elements in the Detail section from a Template.
If I use dynamicReportBuilder.setTemplateFile(TEMPLATE); and dynamicReportBuilder.addConcatenatedReport(subreport); to insert the subreports in the detail Report, which is loaded from the Template, the previous defined elements in the Detail setion of the report template dissapear. So I am looking for the way to conserve these elements.
Based on your comment it seems like one of two things is happening.
1) You have the sub-report defined in the Detail band of the Template file.
In this case it will not work. The Detail band in the template file should be empty. If this is the case it is more than likely just ignoring what ever you have there and doing everything else. Check out the HOW-TO Use custum jrxml templates for more information.
2) dynamicReportBuilder.addConcatenatedReport(subreport); does not do what you think it does.
This method appends a second report to the end of the first report. Think of it more as a batch. It is the same thing as setting a value for JASPER_PRINT_LIST as an export Parameter when using the Jasper Reports API directly. Check out the HOW-TO Add Concatenated Reports for more information.
Dynamic Jasper is a great library, but is really only designed to work with standard tabular reports. It has support for some advanced features, including sub-reports, but it can be limiting.
From what I can find so far, it appears you can only add sub-reports to the Group Headers and Group Footers. So in your case you will probably need to add a Group to report first using GroupBuilder. Then you can add the sub-report to the Group Footer. The trick for the group is to make sure that each row will end up being its own group by picking the appropriate fields to group on.
You can look at the code examples in the HOW-TO Add labels in group header and footer to see how to build the groups.
To see how to add sub-reports to the report you can use DynamicReportBuilder.addSubreportInGroupFooter() method. For more details about this part and an example check out HOW-TO Add Subreports (fast way).
The other option you have is to not use Dynamic Jasper for this particular report, and just use jrxml files and the Jasper Report's API to do it yourself. It may or may not be easier depending on your setup.
By Ricardo Mariaca. This code is the solution, Thank to Ricardo and Dynamic Report
private void build() {
try {
JasperPdfExporterBuilder pdfExporterBuilder = export
.pdfExporter(PDF_FILE);
JasperReportBuilder jasperReportBuilderMain = report()
.columns(
col.column("Item", "item", type.stringType()),
col.column("Quantity", "quantity",
type.integerType()),
col.column("Unit price", "unitprice",
type.bigDecimalType()))
.setDataSource(createSubreportDataSource())
// .detail(cmp.subreport(createSubreport()))
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL);
JasperReportBuilder jasperReportBuilderDisclaimer = report()
.setPageFormat(PageType.A4, PageOrientation.LANDSCAPE)
.summary(cmp.subreport(jasperReportBuilderMain))
.summaryWithPageHeaderAndFooter()
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL)
.columnHeader(
cmp.text("first page header").setFixedHeight(50))
.columnFooter(
cmp.text(DISCLAIMER).setStretchWithOverflow(true)
.setFixedHeight(250))
.pageHeader(
Templates
.createTitleComponent("Ricardo Mariaca Approach"))
.pageFooter(Templates.footerComponent).show()
.toPdf(pdfExporterBuilder);
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createSubreportDataSource() {
DRDataSource dataSource = new DRDataSource("item", "quantity",
"unitprice");
for (int i = 0; i < 180; i++) {
dataSource.add("Book", (int) (Math.random() * 10) + 1,
new BigDecimal(Math.random() * 100 + 1));
}
return dataSource;
}
}

iReport, subreport does not appear

i'm trying to add subreport to report.
I have setted connection type to "use a connection expression" and the expression is $P{REPORT_CONNECTION}.
My subreport contains a simple query and some static text, when i test it all works good, but when i test mainreport the subreport does not appear.
I have some static text in subreport, this one should be display always, isn't true? But i can't see it...
During compilation i have no errors, and subreport path seems correct becouse a message say "subreport.jrxml already compiled.".
What can i do?
Thanks.
The solution is pass HIBERNATE_SESSION as parameter from master report to subreport.
Please Right clik on sub report and clik on open sub report if your sub report gets open then your reporyt is connect with your sub report. if subreport is not open do the right connection for that.
if your subreport is work for the parameter value with seperatly and displyes the static text and detail band values it is sure that the report will come ffrom main report.
but the report displays only static text and the text is in title or page heder, then you have to go to the report property and set the output when no data then choose diplay all section data from combo. your static text will apper from main report.
When you add a sub-report in your main report, the sub report expression will refer your locally saved sub-report path. Ex: "C:\abc\xyz.jrxml".
Now you can preview your main report containing sub-report in your ireport.
Once you publish the main report in Jasper server, the Sub report gets loaded into jasper repository and its expression becomes "repo:Repositorypath.jrxml".
Once sub-report contained report is published into Jasper repository, its path will always refers to Jasper repository path and because of this reason, you will not be able to Preview the main report in Ireport.
So, execute the report in jasper server directly once you publish the main report instead of previewing or opening the subreport in Ireport.
Thanks,
Srikanth Kattam

Subreport values are not displayed in main report

I have my main report which contains 1 subreport. When I run my main report the subreport values are not displayed in my main report, but when I run my subreport individually I can see the output in PDF format. Can anyone help me in fixing this issue?
First see the connection with right click on the report and click on open subreport if its working then clik on the subreport go to the subreport property and see the parameter passed to the subreport is correct or not if not please pass properly. also see the parameter value required for the subreport is that comming from main report.
Means : if your subreport require account_id = 5 the it must that main report passes the value 5 to the subreport.
You need to call the SubreportProcessingEventHandler and add the datasource.
Step 2: Check the properties of subreport.
If it does not need any parameters from main report. Do not add any.
The path of the repo