dynamicjasper addConcatenatedReport in a frame - jasper-reports

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;
}
}

Related

ActiveReports 8 - Section Report With Main Report and SubReport

I am developing a Section report using ActiveReports 8. I have a Main report with a detail line that has five text boxes bound to data. The detail line also has two unbound text boxes that are defined but are not bound to data. I am attempting to populate these two unbound fields by data coming from the subreport.
I am part way there BUT the unbound fields are getting populated one detail line late. If this makes sense?
Have tried using different events ... cannot seem to find the right combination.
You can get data from the SubReport by creating a property or two in the SubReport and access the property values in the main report's Detail Section's Format event and assign it to the unbound TextBoxes. Something like:
private void detail_Format(object sender, EventArgs e)
{
subReport1.Report = rpt;
rpt.Run();
textBox3.Text = rpt.SubReportValue.ToString();
}
private void MainReport_ReportStart(object sender, EventArgs e)
{
rpt = new ChildReport();
}
We have also replied to you on the ActiveReports forum post with a demo application - http://arhelp.grapecity.com/groups/topic/activereports-8-section-report-with-parent-and-subreport/

set subreport via code

I have three reports (main.rpt, sub1.rpt, sub2.rpt).
In the main.rpt, in section 2, I have a empty subreport (without connection to the data).
I would decide, via code c#, whether to show sub1.rpt or sub2.rpt inside subreport in section 2 of the main.
I use this to show main report:
r.Load("main.rpt");
r.SetDataSource(dset);
crystalReportViewer1.ReportSource = r;
// HOW SHOW sub1.rpt or sub2.rpt in main's section2?
Suggestions? Thank you very much
Try:
r.Subreports("Your Sub report").SetDataSource(dset)

Jaspersoft studio summary and subreport

I have a problem with jaspersoft studio, the problem is that I want to put the Subreport on the very last page in the document. So my idea was to put it in the summary, but then I got something strange...At the end of the PDF generation the subreport is on the last page, BUT the sub report is not complete there is stuff missing :/ It is just printing out the last values
Consider the following example:
I have 3 Parts, Part-1, Part-2, Part-3
After finishing the part-3 the subreport should be visualize with some of the information of part 1-3, but the subreport in the summary just contains information from the part 3
I use a XML Datasource
Can anyone help me, please?
You have to think of the context of the summary band and the sub report.
Is a variable from part 1 and part 2 being passed to the sub report? Is the same variable being passed from part 3? If so then it is being overwritten.
It really depends on the source of the information for the sub report, but the timing and context are likely the culprits here. You may need to create three sets of variables to contain what you want or just pass something into the sub report and let it gather the information for the three parts on its own.

How to conditioanlly hide group header in crystal report based on a column value in details section

I hope some one must have dealt this situation before.
I have a crystal report and on that report I have different sections including headers ,detail and footer. I'm displaying parts related information on details section and description is one of the fields thats being displayed.
So now based on part's description(in detail section)I have to display some text on the page header. So I have to look for part's description for every single part ,and if even a single part has the given description out of all the parts I have to print a message on report header.
My assumption is to use conditonal suppress option at the page header section, but not sure how to check for values from details section at the page header level.
Any help will be highly appreciated.
Thanks
NAF
Here's the way I would approach it.
Create a formula which returns 1 when your condition is met- otherwise 0. For example:
if {table.field} like '*acid*' then 1 else 0;
Then your conditional surpression can sum your new formula- and if the result is 0 it will hide the message.
sum({formula}) = 0
If you want to display it in Report Header then i would use a SQL Expression to conditionally suppres the text you want.
The SQL Expression
(select count(1) from dbo.TABLE where description = 'my_description')
Then in the Suppress formula:
{?SQL_EXPRESSSION} = 0

JasperReports: unrecoverable multipage subreports

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