Jump to content
Changes to the Jaspersoft community edition download ×

how to "join" master and subreport


2004 IR Help

Recommended Posts

By: Daniel K. - dantest

how to "join" master and subreport

2004-06-25 08:26

Can someone please give me a pointer on how to join the master and a subreport?

 

The tutorials don't seem to work for the newer 0.3.1 version I'm using. I am so confused :(

 

 

 

 

 

By: Daniel K. - dantest

RE: how to "join" master and subreport

2004-06-25 12:56

Thanks for the help Rick. I applied as much as I can understand from your response, but it's not working.

 

Yep, my master and subreports works fine individually. My situation is quite simple, I have orders and ordered items so my master report shows a list of orders. Master report query:

"select order_id, order_date from orders"

 

I am trying to get the list of items per order for the subreport, using subreport query:

"select item_id, order_id from order_items"

 

So, if I follow the tutorial correctly, the "joinable" version of the subreport query should be:

"select item_id, order_id from order_items where order_id = $P{ORDER_ID}"

 

In my *master report*:

 

1. My subreport element's properties, under the "Subreport" tab, it only has "Use connection expression" with the value of $P{REPORT_CONNECTION}, in blue color. The top box, "Parameters Map Expression" is empty, and "Using cache" checkbox is checked. Then, in the "Subreport (Other)" tab, it has "Image Expression Class" of java.lang.String, and "Subreport Expression" of $P{SUBREPORT_FILE_NAME} in green color. Below, it has "ORDER_ID" as parameter and $F{ORDER_ID} as the expression. Am I missing anything else here?

 

2. Under "Report Parameters", it has 2 defined:

 

a) Parameter name: SUBREPORT_FILE_NAME,

Parameter class type: java.lang.String,

Is for prompting: CHECKED (is this right? tutorial had it checked),

Default value expression: "C:\iReport-0.3.1\myreports\OrderItems" (note I left out the .jasper extension since the compiled files don't have it. Weird.)

 

b) Parameter name: ORDER_ID,

Parameter class type: java.lang.Double (this is actually of type NUMBER in oracle schema),

Is for prompting: UNCHECKED (left at default),

Default value expression: new Double(100) (just a test value for order_id=100, as per your tip)

 

In my *subreport*:

1. Under "Report Parameters", it has 1 defined:

a) Parameter name: ORDER_ID,

Parameter class type: java.lang.Double,

Is for prompting: UNCHECKED,

Default value expression: <BLANK>

 

So what else am I missing or doing wrong? I guess I still don't have a concrete understanding of how the report parameters work, and how they get passed from one report to another... Thanks again for your help.

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-06-25 13:45

it would be helpful for you to post the error messages, or at least describe what you mean by "its not working" more fully. Looking at what you've listed, it looks like you've followed the steps correctly. Without seeing the error, it is difficult to see what the problem might be. Is it a runtime or compile-time error?

 

Rick

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-06-25 13:58

Also, are you sure your subreport is working by itself. Looking at your parameter reference in your SQL where clause, it appears you are missing a ! symbol. Try "select item_id, order_id from order_items where order_id = $P!{ORDER_ID}"

 

 

 

 

By: Daniel K. - dantest

RE: how to "join" master and subreport

2004-06-25 14:54

I got it working! There is a bug with iReport in that it does not allow me to modify the subreport's query from a "working" one such as:

"select item_id, order_id from order_items"

to get the info for the fields, and then change it to:

"select item_id, order_id from order_items where order_id = $P{ORDER_ID}"

At this point, the "OK" button gets greyed out. I was trying to get around that by closing the window via the "X" at the top, and issued a "compile only", but it seemed that iReport reverted the query in the background and the compiled version isn't the new query. I verified this by manually changing my Subreport.jrxml query to include "where order_id = $P{ORDER_ID} and it worked!

 

This is a *really* bad bug, and prevents subreports from working. :(

 

 

 

 

By: Daniel K. - dantest

RE: how to "join" master and subreport

2004-06-25 15:02

LOL, yes you are right, I misunderstood what you meant by "subreport working" because it worked when I didn't have the where clause. I then put it in with $P{ORDER_ID} (not without !) and it didn't work -- I thought the ! was the cursor! LOL.

 

Now it all works as expected, THANK YOU SO MUCH Rick!

 

By the way, do you know what the purpose of the "Is for prompting" is? The tutorial has it always checked for each parameter but I had mine unchecked for ORDER_ID as stated above and it still worked...(?)

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-06-25 17:01

Glad you got it working!

 

As for the "Is for Prompting" attribute, I believe it is for use when you are running the report. In our reporting framework here, when you execute a report, the framework throws up a parameter dialog box for the report being run. This dialog box "prompts" for user to fill in values for the parameters. Only those parameters that are marked "Is for Prompting" are displayed on the ui. The others are hidden parameters that either do not get passed in dynamically (e.g. subreport path), or set by the application logic insted of by the user.

 

 

 

 

 

By: Daniel K. - dantest

RE: how to "join" master and subreport

2004-06-28 08:30

Oh I see, thanks again! I hope this thread will be useful to new iReport users for creating subreports. I'm going to link to it. :)

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-08-18 10:57

Please read the thread at the URL below. It may help you:

 

https://sourceforge.net/forum/message.php?msg_id=2635951

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-06-25 11:19

Daniel,

 

While the subreport tutorial is for earlier versions, the essentials of it are still valid. The key things you need to do to configure you master report to call a subreport are the following:

 

1. You need to define the connection/datasource expression for the subreport in the subreport properties as $P{REPORT_CONNECTION}. See Step# 14 in the tutorial.

 

2. You need to define the subreport expression for the subreport in the subreport properties but on the second tab (other). See Step 15 in the turorial. The value for this expression should be $P{SUBREPORT_FILE_NAME}. It doesn't actually have to be "SUBREPORT_FILE_NAME." You can pick whatever string you want to use. However, you must use the same string when you define the parameter in the step 4 below.

 

3. Add any parameters you will be using to pass data values to your subreport. The parameter name should match the name of the parameter that is used in the subreport itself and the expression should reference a parameter or field in your master report. I think this may be a missing step in the tutorial.

 

4. Now in the report parameters window you will need to add and define the parameters you referenced in your subreport element definition. You need to add the SUBREPORT_FILE_NAME parameter and set its expression to the location of your subreport jasper file (e.g. "c:\jasperfiles\mySubReport.jasper"). Notice that you have to escape the backwhacks. The jasper file will only be there if you have compiled your subreport already. Also you will need to create any parameters that your subreport parameter expressions reference (i.e., any parameters you are passing to your subreport). TIP: set default values for you parameters here so you can test the subreport in iReports. The default values will be passed to the subreport.

 

You do not need to define the REPORT_CONNECTION parameter. It appears to be a built-in parameter.

 

5. You need to make sure you've defined parameter in you subreport that match the parameters define in the subreport element in the master too. If the don't match, then the data will not be passed to the subreport.

 

6. Save and compile

 

At this point, you should be able to test your report assuming your master report and subreports are already working on their own.

 

 

Lemme know if this helps.

 

Rick

 

 

 

 

 

By: Rick Millar - rmillar

RE: how to "join" master and subreport

2004-08-18 10:58

oops... wrong thread...

 

 

 

 

By: neptune22 - neptune22

RE: how to "join" master and subreport

2005-02-15 21:54

this thread is such a big help. thanks

 

 

 

 

By: neptune22 - neptune22

RE: how to "join" master and subreport

2005-02-15 21:54

this thread is such a big help. thanks

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...