Passing JRBeancollection datasourse to master report and subreport - jasper-reports

I want to pass the JRBeancollection datadourse to main report and from main report to subreport.. I have included this subreport in summary section of master report..
please mention the steps i want to do in ireport including the inbuld parameters how to set.

Finally I have done it.
Actually datasource was not going in subreport. So I have changed the property of when no data to all sections, no data...
Then I have passed the collection variable where I have fetched the subreport records.
By using parameters.put("shape_data_all", allShape_Caliberation);
Then I have created a parameter in main report. And changed its class to java.Util.Collection.
Then in subreport property, connection type= Use a datasource expression
Data Source Expression new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{shape_data_all})
Then added the fields in the subreport same as I am having the bean properties.
Thank you.

I'm not sure, but try this:
<subreport>
<reportElement x="261" y="25" width="200" height="100"/>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"]]></subreportExpression>
</subreport>
Of course you have to use the "subreportExpression" as you are doing in your report, this is just a sample, the useful line for your problem is where the "dataSourceExpression" is placed.

Related

Jasper Subreport Only Populating On First Page - Java [duplicate]

This question already has an answer here:
How to use same JRBeanCollectionDataSource on multiple sub reports?
(1 answer)
Closed 1 year ago.
I have a main report with a subreport in the group footer. The goal is to show this subreport on every page. In Jaspersoft Studio this works perfectly but when I compile and fill the template in my Spring service, the subreport is only filled on the first page. When I put "All Sections No Detail" for "When No Data Type", I only see the column headers. I have spent hours upon hours trying to debug with no success. Below is the jrxml and java code.
JRXML
<groupFooter>
<band height="144">
<subreport>
<reportElement x="70" y="90" width="642" height="30" uuid="47af6568-4e1c-4dc4-8688-dfb4d6e17bbc"/>
<dataSourceExpression><![CDATA[$P{TEMPLATE_DATA}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{TEMPLATE_XML}]]></subreportExpression>
</subreport>
</band>
</groupFooter>
Java Code
Map<String, Object> parameters = new HashMap<>()
parameters.add("TEMPLATE_XML", compiledSubReport)
List<entity> entityList = util.getEntities()
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(entityList)
parameters.add("TEMPLATE_DATA", data)
return JasperFillManager.fillReport(mainReport, parameters, mainDataSource)
Data source objects cannot be used several times, you need to create a fresh one each time the subreport is displayed.
You can do that by passing entityList to the report as a parameter, and then using this for the subreport:
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{ENTITY_LIST})]]></dataSourceExpression>

Jasper subreport not showing

I am using Eclipse JasperReports Studio and have run into a problem I can't resolve. I have a pretty basic report with detail fields which return about 30 rows. I have a subreport I want to incorporated into the main report but when I add it nothing displays. I have tried adding it to the Column Footer, in the Page Footer with my Page x of x fields, and in the detail field. Which didn't work so well since it added a blank spot between every row retrieved. I have other reports with sub-reports in various bands and they all work fine. Here is the subreport code for the col footer:
<columnFooter>
<band height="110">
<subreport>
<reportElement isPrintRepeatedValues="false" x="0" y="10" width="555" height="100" uuid="34205e71-ec6b-422c-aa27-057678430999"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["The_Report.jasper"]]></subreportExpression>
</subreport>
</band>
</columnFooter>
Any obvious reasons why this won't show up? I don't get any errors and the main report runs fine. The subreport works fine on it's own and it is in the same directory as the main report. I compiled it there and the .jasper file is there as well.
I came across the same problem when using subreports.
In the editor: deleting the content form connectionExpression
And putting $P{REPORT_PARAMETERS_MAP} in the Parameters Map Expression did the trick for me.
Source code: <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
Verify that the Subreport Expression is pointing to the correct/expected subreport. There are times (often due to copying and/or hand-editing existing JRXML files) where the Subreport Expression is still pointing to the subreport Jasper file of the original, Main report. I just ran into this case, myself.
Make sure that
<subreportExpression><![CDATA["The_Report.jasper"]]></subreportExpression>
isn't supposed to be something like
<subreportExpression><![CDATA["The_New_SubReport.jasper"]]></subreportExpression>
or contain the Subreport directory like
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "The_New_SubReport.jasper"]]></subreportExpression>
You should also verify that your subreport doesn't require data in order to display. If it does and your query doesn't return any data, you can do the following:
SELECT FIELD_NAME
FROM TABLE
WHERE KEY = $P{KEY}
UNION ALL
SELECT NULL AS FIELD_NAME
FROM DUAL WHERE (
SELECT COUNT(*)
FROM TABLE
WHERE KEY = $P{KEY}
) = 0
A quick reminder, after double checking that you have the correct values for all the <subreportExpression> elements. Make sure you Build All the project files.
The main report will call the compiled version of the subreport. So once you have tested and saved your subreport, click the Build All button or click on the Menu option under the 'Project' menu at the top of the window.

How to pass CSV Datasource to subReport

I need your help in passing csv datasource to subReports .
I would highly appreciate your suggestion or solutions.
I am using iReport 5.0 professional version.
I have a very complex report and that report fetch data from multiple (approx 10) csv files.
I have created subReports for each section of the reports and each subReport is working fine as a indivisual Report.
But when i try to integrate all the subReports into a main Reports , then i am not able to pass datasource to the subReports.
In Main report, i created a parameter called CSVDS of type net.sf.jasperreports.engine.data.JRCsvDataSource with its default value as following:
new net.sf.jasperreports.engine.data.JRCsvDataSource(new File("D:\\client\\data\\SR1.csv"))
and in order to make sure that CSVDS is getting value from SR1.CVS , i added a textbod with following expression and it returned true
$P{CVSDS}.next() -- return true --which means that CSVDS gets populated from the data from SR1.csv
Further, i passed $P{CVSDS} as datasource to the subReport
<subreport>
<reportElement uuid="2f0d77ac-ce39-4487-8f31-0e15e03f5dfd" x="0" y="0" width="592" height="437"/>
<dataSourceExpression><![CDATA[$P{CSVDS}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "P1.jasper"]]></subreportExpression>
</subreport>
but the subReports was coming blank.
So, overall, i would like to know how can i pass csv datasource to subReports .
PS : I have tried almost all the solutions available on Stack overflow and Jasper community site but nothing worked for me.
You need to cast the datasource expression to the proper type:
<subreport>
<reportElement uuid="2f0d77ac-ce39-4487-8f31-0e15e03f5dfd" x="0" y="0" width="592" height="437"/>
<dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRCsvDataSource)$P{CSVDS}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "P1.jasper"]]></subreportExpression>
</subreport>

JasperReports: iterating List inside JRXML

In one of my report requirements, I need to show multiple rows with customized data.
For customized data, I used REPORT_SCRIPTLET feature which is filling a List with data objects. Till this point everything works.
How can I pass the above filled List to JRXML, and iterate over rows to show them in the report?
I did searched and found few posts and as per them, I should used SubReport with JR Data Source.
Please help in achieving the goal. I am not able to find concrete samples or syntax for the above problem.
Thanks in advance!!
Regards,
Rawat
Thank you for the snippet.
Apparently, I am also using the same syntax but I am confused on the "listNameWhatEverYouWantToPass".
In my case, "listNameWhatEverYouWantToPass" is an List of Objects say of Class TestObject having 4 fields with setter and getter methods.
It is defined in JRXML as
<variable name="listNameWhatEverYouWantToPass" class="java.util.List" calculation="System"/>
"listNameWhatEverYouWantToPass" will bet set by a Scriptlet Class inside afterGroupInit function as
List<TestObject> testList = new List<TestObject> () ; // Is it correct??
// add TestObjects to the list
this.setVariable("listNameWhatEverYouWantToPass",testList);
How can I access the data from indivisual objects from the List in subreport.jasper?
Thanks,
Rawat
here are code for add subreport in main report.
<subreport>
<reportElement uuid="cb31b535-0484-4a63-a1af-b6737d937474" positionType="Float" x="0" y="60" width="515" height="15"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(listNameWhatEverYouWantToPass)]]></dataSourceExpression>
<subreportExpression><![CDATA["/path/to/subreport.jasper"]]></subreportExpression>
</subreport>
hope it will help you.

JasperReports: How to pass parameter to subReport

How to pass parameter to sub report in JasperReports?
I'm able to pass the parameter to master report but I'm not able pass parameter to its sub report.
Can any one give me the solution for it?
Try using iReport if you are not.
When viewing a report within iReport you can select the properties of the subreport within the main report.
In this there is an option in Subreport properties called Parameters. Using this you can pass parameters to your subreport.
Select this and click the Add
button.
Then click the button right of the
Value expression Box
Next an option screen will pop up
where you can select the parameter
from the master report you want to
pass.
If you want to do it via xml here's a quick example.
<subreport>
<subreportParameter name="XML_ID">
<subreportParameterExpression>
<![CDATA[$P{MASTER_REPORT_PARAMETER}]]></subreportParameterExpression>
</subreportParameter>
</subreport>