Best approach with Jasper Report - jasper-reports

I have a requirement to generate reports in PDF and Excel format. For the same I have chosen Jasper. Now require some help from your side to identify the best approach on the same.
Note - My queries are dynamic in nature.Like in some scenario then will provide name in some scenario they will provide dates not name and in some scenario both.
Approaches I have identified are given below.
We can create data source and query in JRXML and execute the same.But not sure query will be dynamic or not. I am personally not prefer this approach because from java I can pass the connection from pool.
We can pass the query and connection both from the Java side and then Japser will execute the query.
We can query in java and then pass the List of bean to the Jasper for report creation.
Now need some suggestions on the best approach among above and also of any approach suggested apart from the above.

To me, option 3 is best. I did that previously.
For mine, I had a master report containing conditional sub-reports. To do that, I have build sub-report's .jasper from their .jrxml and passed my List of bean so that I don't have to re/compile the .jasper from .jrxml again(My master report was in .jrxml and condition for sub-reports where set there).
Another advantage is, you don't have to change your jasper files if you want to change your logic in query level-just leave them untouched once done.
So, I think , option 3 is good to go.

Related

How do I create a loop for subreports?

Adding a subreport into a report with Java and Jasper Reports was easy enough, but I am having trouble making that subreport into something loopable.
The code in Java was simple enough: create report and loop through the parameters to generate subreports. The report generated at the end is a XLS file.
The hassle starts with Jasper Reports since the second iteration complains about the subreport datasource ID already being in use, but then if I generate dynamically the names in the Java code, the Jasper Report won't compile since the subreport's database name is fixed in the XML.
I could, in theory, just create several of the reports with a single subreport and then attach all of them together, but that doesn't feel optimal. How can I create the looped reports then? Is it some sort of parameter to be given in the XML from Jasper Reports or is it impossible to be done and I must use the multiple reports strategy instead?

Would anyone explain me how to add a data source to a "part" of a Report Book?

I am trying to add a data source to a "part" of a Report Book. Or I should say passing the information to the fields on that "part" of the ReportBook( or why not, the Main Report). I have come to realize that this is not exactly how things were done with MainReport and Subreport(s). This is a new concept of jasper 6.2.0, so is not exactly the old known subreport and traditional way of doing things(or is it? Do not know..., please if you don't main, explain that too, thanks).
I have read a lot of examples out there ( see one here), of how to pass data source through jasper parameters and then, utilize those parameters referenced in , but it does not seem to be the same way when working with "parts" of a Report Book.
I can provide more information, but essentially what I need is to pass that data source to the part, that refer to my other report (or subreport if you will) named Content.jrxml, so the other report can print/render the right information of those fields. This report contains fields and no information is passing to those fields there went I print the Report Book to pdf. those fields are showing as null.
However I am able to pass parameters successfully is just with passing the fields values and the data source in general, which I have a problem
Does anyone have done or deal with this before or knows of a good example/tutorial that could point me to the solution?
Please help me, I don't know what else to do :(
Thanks in advance!
Sorry, it took me a long time to post back. I find a solution after Theodor (Jasper API main author give me some insights) and here is it!
So, for the Jasper Report engine to handle multiple data sources passed to the report, you have to take into account 2 essential things:
First, for every data source that you want to pass to the Report, you will need to create a new instance. Jasper engine consumes each data source iterating over all the elements in it. When it gets to the next page, there won't be any data, fields or information to read from and fill up the fields on that particular page. Therefore, information won't show up (null) or "blank", depending on the report template configuration.
Last, make sure you pass a new JREmptyDataSource() when filling the report and pass the data sources instance as parameters, and later as sub-parameters for each individual page. Like this:
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() );//new JREmptyDataSource()
That way main report, or the wrapping report (the book), does not use any data source of the pages instances (if it does not need it, of course) and each page will get a data source, through the parameters.
Ultimately, on runtime, it the page of the book can consume individually each data source without affecting each other.
Let me know if this makes any sense?
Thanks

How to Query a Web Service (XML) From a Subreport?

I apologize if this has been already asked but my searches have had little luck. I've also tried MSDN forum's, but its obvious that I need the big guns for this one ;)
I am using VS2008 (SSRS 2008 R2) to create a series of subreports. Each Subreport queries 1 or more Web Methods from a WCF Web Service.
When I run an rdl as a stand-alone report, everything renders properly. When I run that rdl as a subreport, I receive an error recommending that I check the log (details, and steps to reproduce below.)
Simple Test (No Subreports):
Using the instructions found in the article Reporting Services: Using XML and Web Service Data Sources I was able to create the necessary Shared Datasets for each web method.
I successfully created a report (SubTest.rdl) utilizing a Shared Dataset for a Table.
The dataset's underlying web method contains no parameters (trying to keep it simple).
SubTest.rdl renders correctly!
So far so good.
Test 2: Master/Subreport structure
created a Parent/Master report (MasterTest.rdl)
added a Subreport Report Item, and specified "SubTest.rdl"
Note: No Report parameters are specified, as SubTest does not have any parameters defined.
I receive the following error during the rendering of the MasterTest.rdl report:
Warning 1 [rsErrorExecutingSubreport] An error occurred while executing the subreport 'Subreport1' (Instance: 5iS0): Data retrieval failed for the subreport, 'Subreport1', located at: /SubTest. Please check the log files for more information.
Additional Testing:
To ensure that my subreport is properly defined in MasterTest.rdl, I altered SubTest.rdl. In SubTest I removed the DataSource, DataSet, and Table from "SubTest.rdl" and insterted a TextBox filled with the words "Output From Subreport". This rendered properly in the Master report, indicating that the problem specifically relates to my Web Service Datasource/DataSet.
Questions: :(
Is there a way to accomplish this task?
If this is not possible, can anyone suggest a workaround for providing Web Service xml to a subreport?
Also, per the error message: Any idea where I can find this log? (because this is running in Visual Studio, checking the SSRS logs folder on my local machine did not help, nor did running VS with logging enabled.)
A workaround that I could not get to work:
I tried to follow the instructions in the linked article for passing XML to a subreport as a parameter, but
The master passes the xml as a scalar string. Because I am querying
a web service and not using a data set where each row contains a col holding the XML, I only have the resultant dataset to work with. Basically I need to convert a data set to a scalar.
I had difficulty following the instructions (even if I could solve problem
1, I'm not even sure that I properly defined the dataset and
parameter - how do I get fields when the data is not known until
runtime?)
Thank you for any help you can give. This has been driving nuts for days!

SSRS 2008 - Expand and Collapse subreports

I am dealing learning SSRS 2008. I want to do a report that is a little bit more complex.
I would like to have a row with information about "Object": name, id, description, etc. And I would like to have a + sign in this row, so I can expand/collapse rows that are regarding "Comments" about that object, with columns like "comment", "date", etc.
I first tried the "Grouping" approach, but I got to a dead end because the groups would use the same header.
Now I am trying to tackle it with a subreport.
The first problem I had is that I couldn't find the query designer in VS2008, so I started the SQL Reporter Builder.
Is there any way to use the Query Designer inside VS2008?
Then I created my report and my subreport as different report files, because I thought I would be able to use the subreport properties to select the subreport file and add it, but I was wrong. How can I add it? Do I have to publish it?
I just found out that I can't use the rdl file from SQL Report Builder in Visual Studio (it doesn't recognize the file extension, in VS2008 it is rdlc).
I am basically lost.
Could someone give me some guidance?
Thanks,
Oscar
This was asked a while ago but you haven't closed the question so I assume you still need an answer.... Are you looking to add the drill down feature to your report?
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/creating-a-basic-drilldown-report-in-ssr-2005
http://www.sqlservercurry.com/2009/08/creating-drill-down-report-with-sql.html
If not... I am confused at what you are looking for and if what you want is really intended to be done in SSRS.
And... are you using subreports because the Object information and the Comment information is on different servers or data sources? Because it seems like you would want to use grouping for this, and group by the objectID and have the comments below.

Composite reporting, Crystal Reports difficult to manage

I was wondering if someone had a suggestion on how to best do composite reporting.
I have tried to accomplish this with Crystal Reports [CR] (The one that comes with VS2k8) but for a codemonkey like me, it's hard to grasp the design part...
I have found that CR works nicely for reporting on tabular and repeatable data, but I can't grasp how to do what I want it to do.
What I want is a nice front-page, with title, subtitle and possibly some other text.
Maybe a TOC.
A summary report, consisting of some calculations and text-summaries calculated beforehand (not using the reporting tool).
Then a listing of one type of data, normal tabular.
Then another type of data, also tabular.
Then a drill-down on the first type of data. (Every "line" in the first type has 1..* associated items).
It looks to me like I have to do them all in separate reports, then "concatenate" the resulting reports to one another to get one report. And the front-page and the summary page I have no idea how to do at all.
Is there a better tool for doing this? Or does anyone have a good "quick-start" on composite reporting with CR? :)
EDIT: Oh, and these will only be used in printed-form. So no dynamic drill-down and such are necessary.
I create sub-reports and insert them into a footer section of the main report to create composite reports, using seperate reports as you suggest. I've searched myself, and failed to find any reasonable alternative. This approach works well enough and results in a single report file when done.
In my experience, Crystal is a pain in the butt for doing anything like a fixed page layout (ie: the title page). I usually put the title page in the report header (make sure to select "new page after" in the section options). Everything else pretty much has to go into subreports.
If you need to share totals and such between subreports, you need to use a shared variable in a formula field:
shared numbervar whateverTotal:= sum({whatever});
and then in the following reports, just use:
shared numbervar whateverTotal;