I'm totally new to the reporting world and my first trials are with iReport 4.1.1
I'm looking for the right way to have multiple queries into the same report... I founded a post wich enumerates 3 methods: using sub dataset, using sub report, using tables (http://stackoverflow.com/questions/3927183/using-multiple-tables-in-ireport).
Could someone be more expansive about that? Even a link redirection would be welcome.
Thank's a lot!
Depending on what you're trying to do, there are also sometimes some tricks for avoiding multiple queries in the same report, but I'll start by telling you a little about the three multi-query methods that I know about so you can see which one best applies to you, and then if I have time, I can try to give you some pointers on how to use whichever method you select.
First, probably the easiest to understand is the use of subreports: you can develop completely separate reports for each section of your report that could even be run independently if that's useful (in fact, I'm not sure there's even a way to prevent that). That kind of makes the development and testing easier, as you first write the separate reports and make sure they work just the way you want. Then you write the master report that contains the subreports. A frequent area of confusion when you try this last part is passing parameters back and forth between the master and the subreport. Probably the most common requirement is to take input parameters from the user in the master report and pass those values on to the subreports that are really doing all the work. That's not very difficult. Slightly less straightforward is returning values from the subreport to the main report--the method isn't really any trickier--only the concept and under what circumstances it might be helpful is. I've already listed some advantages of subreports: you can develop them separately and then tie them together, you get to use all the features of a report (headers, etc.) on each part of your report), and dragging subreport components into a master report doesn't introduce a LOT of new concepts. One drawback they have is that they require multiple source jrxml files, which can make them run slower (because of multiple compiles required) and can also make the difference between running them in preview mode in iReport vs. deplying them on JasperReports server pretty complicated/frustrating. I have some notes I took a long time ago that can keep you from constantly having to change the syntax for the subreport syntax back and forth, but it still takes some getting used to.
If you instead decide to write a single report and drag a List or Table component onto your design area for each section, you will be creating a subDataset. These are a little less flexible, but they usually run faster than subreports and you have the benefit of not requiring additional resources such as additional jrxml files, which makes deployment simpler. Passing values back and forth between a main report and a subDataSet is actually very similar to how it's done with a subreport. I'm actually on Professional version 3.7, so I only have List, not Table yet. With List at least, some limitations are that you don't have groups, headers, summary, etc. like you do with a subreport...essentially you just get simple detail lines for each result set row of your subdataset query. Another limitation I've (re)discovered...at least in version 3.7 is that a List won't continue on to the next page, even if there's more data that should be displayed. Actually, I have a Summary band with a list in it, and when I run it in iReport preview mode, it goes on for five pages, and it also exports just fine to PDF. But when I deploy that same report to JasperServer, it stops at the bottom of whatever page it starts on. I just found a post from back in 2009 where this was being commented on, and sure enough, I ran into that problem just yesterday.
If you decide that a List or Table is for you, here's a post I made quite a while ago with some of the basics on how to create a List component: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=81368&topid=81372
If you decide to use a subReport, there are also several posts on how to do that, including passing values back and forth, which has to be one of the most often asked questions in this forum!
I am trying to use lists. Above, you indicated that it possible to pass values back and forth between a main report and a subDataset. I am able to pass values to a list, but I can't figure out how to get values back from a list to use in the main report. How to you pass values back from a subdataset to a main report?
Looks like I'm a liar. You can definitely return values (usually totals, for example) from a SUBREPORT, because when you have focus on a subreport element, there's a place in the properties box where you can open up a dialog to control "Return values". I see no such property on a list (I'm on Professional version 3.7). You can definitely pass parameters, variables, etc. to a List, because I do that all the time, but I was a bit hasty in my generalization of how similar lists and subreports are, just because they both use datasets. Sorry for the confusion and for raising your hopes.