input control to choose subreports?

0

I have a need to run a master report and choose, using an input control, which subreports to include.  The subreports are already built and established reports on their own but now there's a need to print different combinations of them instead of printing them one at a time individually.  I'm hoping to be able to use a multiselect input control.  any ideas?

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago

19 Answers:

0

hi, in my opinion you should only to pass the name of your subrpt like a param.
Follows theese steps:
1- create a param (type String) and check the relative property that allows it to be used as prompt; call this param for example "subRptName";
2- in your main rpt go on the sub rpt properties and modify the (default) subreport expression: $P{SUBREPORT_DIR} + "<nameOfYourSubReport>.jasper"
with this one: $P{SUBREPORT_DIR} + $P{subRptName}.
 

hope this help you

p.s. Remember  that it is  also possible to pass direcly the subrpt jasper file like param

 

Giovanni


 

...La puissance est rien sans controle...


 

 



Post Edited by giobby at 11/07/2009 08:27
giobby's picture
42
Joined: Oct 1 2009 - 6:44am
Last seen: 4 years 4 months ago
0

I think I'm following you.  Basically create as many subreport components as I will need and use the existing reports as the source.  Then change the subreport expression to include the parameter.

Where I get lost is collecting that parameter.  Since I need a multiselect the parameter has to handle a collection right?  Do I just put the $X{} syntax in the main report query?  Like I said, I understand the parameter part on the subreports.  I just don't understand how you pass that in unless it's part of the query.

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0
hi manshack_one,
my english is a little bit approximate, surely i've not understand very well what is your problem.
I think is better to wait another one's reply...
i'm really sorry but i can't understand the 2nd part of your post.


Giovanni


...La puissance est rien sans controle...


 

giobby's picture
42
Joined: Oct 1 2009 - 6:44am
Last seen: 4 years 4 months ago
0

My suggestion:

 

add all the subreports you need to your report.

Use the collection coming from the multi select list to show/hide the unwanted subreports using the printWhenExpression of the subreport elements.

 

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0

This sounds promising.  Now I just need to figure out the printWhenExpression. :)

So will I need a table with the subreport names to bounce the multiselect against?

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

Just create the report like you would have to keep all the subreports.

The set the print when expression of each subreport to something like:

new Boolean( ${subreport_to_show} == null || ${subreport_to_show}.contains("my subreport") )

where "my subreport" is just a key (or a name or whatever) which identifies a particular subreport.

The expression shows the subreport  "my subreport" if the collection is null or if the name "my subreport" is present in the collection.

It's not useful to deal with the subreport name or stuff like that suggested in the previous posts.

Just show / hide the portions of your report you don't want to display based on the user input using this magical print when expression which is available for elements, but even for bands.

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0

Thanks giulio.  This is all starting to come together.

1) Create a multi-select list of values (with the subreport names as the values)
2) Create master report containing a subreport element for each of the reports I want to possibly include. (7 in my case)
3) On each subreport element change "printWhenExpression" value to use the expression you wrote

In your example expression, "subreport_to_show" is the name of the multiselect input control and "my_subreport" is the name of the value in the multiselect list (which has to match the name of the subreport), correct?

 

I think what has been throwing me off the most is thinking of input controls only for the data filtering capabilities where you use $X{} syntax in your sql where clauses. 

 

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

All correct. Please note that the name of each subreport in the multi select (and in the print when expression) is arbitrary (it can be just 1, 2,3, 4, ....) , it has nothing to do with the subreport file name. You should just use a good name to quickly identify which subreport refers to which name (for maintainace propuses first of all).

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0
On my master report, which band would be best to put these 7 subreports into? Does it matter?
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

I'm getting a blank page.

I've tried putting them in the Title band, Detail and summary.  I ended up with this in the printWhen:
new Boolean($P{showSub} == null || $P{showSub}.contains("CAD")) for the first subreport.  I haven't pushed it up to JS but just trying to get it to run inside IR right now.  I added the showSub collection parameter and I tried setting the "when no data" to all sections, no detail.  I created my master report from a blank landscape template with no query at all.  Just an empty report.  Then I dropped the subreport elements in there.



Post Edited by manshack_one at 11/09/2009 22:16
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0
Ok, I didn't have my report datasource set so that was one issue. But I haven't set a printWhen expression on the other 2 subreports and they print when I leave the showSub collection null on the input control but the first one with the printWhen expression doesn't show up.
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0
Setting the name "CAD" on the input control brings that report up now along with the other two that don't have a printWhen expression. Is there something wrong with the expression that it's not evaluating null to mean an empty collection?
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

it depends by what the subreports are used for. By putting the subreports in the detail you'll get the subreports for each record of the main data source, which is probably not what you want, but it's ok if the master has just a single record. In that case you may consider to use more that a detail band (feature available from iReport 3.5.2) and even use the print when expression on these detail bands instead of the subreport elements.

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0

Set your subreport elements position to Float.

 

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0

The subreports really don't correlate with each other.  The master report is really just a container for the subreports because management didn't like having to run 7 separate reports.  The reports do share some common parameters like the date range and location selections but that's about as far as it goes.  There won't be a query for the main report so there are never going to be any details.  I have them in the summary band right now (I think).  I'm going to go and check the float property you suggested and I'll let you know how it goes.

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

Ok, I have three subreports in the summary band of an empty report template.  All three are set to float.  I have a page break element in between each of them.  I set the empty report to the right datasource and my parameters are passing through just fine.  Here's what I have left to resolve.

1) The page breaks are being ignored.  Each subreport following the first one will start prining on the same page as where the other one ends.  If I take off float and set to fix relative to top of the page then the reports will layer on top of each other and still ignore the page breaks.  It needs to print one subreport, then break to a new page, then start the next subreport.  This is the same process no matter which subreports are chosen.  If they don't choose to print the first report but do select the second one then the second one needs to be right at the top of the first page of output.

2) I only put in the print When expression to check my input control for null or the subreport name on the first subreport.  It still does not print the subreport if the input control is left null (by not entering anything).  It will print however if I put in the name of the subreport into the input control.



Post Edited by manshack_one at 11/10/2009 14:33
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

1) try to use the title.... you never know... be sure the page breaks are set with position float too.

2) probably JasperServer pass an empty not null collection, so chage the print when expression like:

 

collection == null ||  collection.isEmpty() || collection.contains("my subreport")

 

Giulio

giulio's picture
30240
Joined: Jan 2 2007 - 4:15pm
Last seen: 1 year 2 weeks ago
0
Nice!

I have the subreports in the summary band but they still show up either way now that I've set the other two options you posted. Set everything to float and check for empty instead of null. Now that I'm past this hurdle everything is falling into place nicely and my future reports will be that much easier.

Thanks!!
manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
0

I've submitted a bug tracker for an issue where iReport is not changing the relative path of the nested subreport.  When you publish the master report using the repository navigator there is a dialog box that prompts to upload the subreport and change the path.  It's only going one level deep though and not changing the subreport's subreport path.  Result is when you go run the report on JS there's an error about not being able to load the subreport's subreport object.

Right now I'm running into a different bug.  Whenever I choose to print the first subreport everything lines up correctly after that.  Each following subreport starts at the top of the new page that the page break is creating.  However, If I don't choose to print the 1st subreport, any other subreport chosen starts printing in the position the subreport element was placed on the summary band.

To get around this I made every subreport element a height of 1.  Then starting at the top I set the first page break to 0, the first subreport to 1, the second page break to 2, the second subreport to 3, etc.... on through the last subreport.  I tried just stacking them all on top of each other but they would ignore the page breaks that way and print on top of each other.  The way it now works.  Each element is only 1 in height and spaced 1 apart vertically.  End result is that if I only choose to print the last subreport it will start 15 down from the top.  I'm not certain what the measurement actually is meaning pixels, pica, points,etc.

manshack_one's picture
Joined: Aug 18 2009 - 9:29am
Last seen: 2 years 10 months ago
Feedback
randomness