List inside a list

Good afternoon. I would like to ask if Jasper supports list inside a list.
Here is an example:
image

In the first list i am using the invoice_id to fetch shipments that involved on this invoice but in the second list

that refers to shipment's cargo details, how can I write in the condition that the shipment_id is the one of the corresponding row?

aigli.karapostoli's picture
Joined: Oct 6 2017 - 5:22am
Last seen: 3 years 5 months ago

8 Answers:

No Problem, I would advice using SubReports (no List-Elements !) for that purpose. Just pass the current primary key down to the SubReport as Parameter and use it for your SubQuery.

hth + regards

C-Box

C-Box's picture
19683
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 months 5 days ago

Good morning dear, many thanks for your reply. 

 

The thing is that even with the subreport , i have to pass the primary key from the first list (a field), not a parameter from the main query,

 so for each row of the first list, a second list to be generated.

 

If this happens with a subreport, please give me further information on how to parse a field from the 1st list.

 
aigli.karapostoli's picture
Joined: Oct 6 2017 - 5:22am
Last seen: 3 years 5 months ago

Well it's clear that you want to pass the current primary key from the field-value ...

So let's try to describe:

In your MAIN Report (jrxml) you have a SubReport1 (as Element)... at this SubReportElement you define a so called "SubReportParameter" with a name e.g. "TopMostPrimaryKey" and as parameter-expression you define the current field (e.g. $F{YourFieldForPrimaryKeyAtMainLevel} )

In your SubReport (jrxml) you then define a "normal" ReportParameter with the same name (e.g. "TopMostPrimaryKey") and the matching class type (Integer/String/whatever)

in your SubReport (jrxml) query you then can integrate this parameter in your where condition (e.g. WHERE SubTable.ParentKey = $P{TopMostPrimaryKey} )

That's actually all. :-)

So you will now just return the results from  the first Main record + the nested records  with the first primary key... then the SubReport returns and the next record from Main query will be called and the SubReport is also called with the second primary key... and so on....

 

now a bit clearer? 

hth + regards

C-Box

C-Box's picture
19683
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 months 5 days ago

Hello dear,

indeed subreports seem to be the solution i am searching for, thank you for the instructions.

A quick question:

While the subreport file fetches data (given subtirid = 577 for example) (image1),

the main report show them as null (image 2).

Data Source Expression : new net.sf.jasperreports.engine.JREmptyDataSource()

I am parsing the field to the parameter as you can see on image 3.

 

Thank you in advance.

 

Attachments: 
AttachmentSize
Image icon image14.35 KB
Image icon image28.96 KB
Image icon 3.png10.08 KB
aigli.karapostoli's picture
Joined: Oct 6 2017 - 5:22am
Last seen: 3 years 5 months ago

In your SubReportElement you just need to define the SubReportParameter by Name... so no $P{} logic is required there for the name of the SubReportParameter.

so just call it "subtirid" instead of "$P{subtirid}"

hth + regards

C-Box

C-Box's picture
19683
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 months 5 days ago

Thank you once again for your reply.

 

I have tried all possible combinations, so SUBTIRID --> $F{SUBTIRID}, as you can see on the attached image,

still does not working.

Any other idea?

Attachments: 
AttachmentSize
Image icon subreport_parameters6.61 KB
aigli.karapostoli's picture
Joined: Oct 6 2017 - 5:22am
Last seen: 3 years 5 months ago

Ok... so "SUBTIRID" it is on SubReportParameters... and what about the ReportParameter in the SubReport (the sub jrxml) itself? There it must have the SAME name (caseSensitive!) as in the parent SubReportParametersMap..... is this so? Otherwise you could perhaps attach your jrxmls

regards

C-Box

C-Box's picture
19683
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 months 5 days ago

Hello C-Box! I managed to find what the problem is.

The connection expresion of the subreport must be the same as of the main report.$P{REPORT_CONNECTION}.

Thank you so much for your replies, your help is much appreciated.

 

aigli.karapostoli's picture
Joined: Oct 6 2017 - 5:22am
Last seen: 3 years 5 months ago
Feedback
randomness