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.
Related
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>
I wish to know if there is a way to include a subreport file (or content) in the master report, instead of providing a file path in the master report through a subreport tag:
<subreport>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA[$F{subreportPathFile}]]></subreportExpression>
</subreport>
I don't want to have two jasper binaries files but just one.
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>
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.
I have a jasper-report that has several subreports. Most of them work fine, but for some reason one of my subreports does not split if it becomes long enough to reach the end of the page, instead it jumps back up to the top of its detail section and continues writing there, overwriting the previous text. I can't see any difference between this subreport and the one that work right. Currently my project uses jasper-reports 1.2.5, but I tried upgrading to 4.0.1 (just for this one report) and the results were the same.
This is the section of jrxml where my subreport which doesn't work is included:
<subreport isUsingCache="true">
<reportElement
x="0"
y="172"
width="468"
height="21"
key="subreport-3"
positionType="Float"/>
<dataSourceExpression><![CDATA[$P{dataSourcePreviousYukonLicence}]]></dataSourceExpression>
<subreportExpression class="java.io.InputStream"><![CDATA[this.getClass().getResourceAsStream("/config/template/subreportPreviousYukonLicence2.jasper")]]></subreportExpression>
And this is the section for one that does work:
<subreport isUsingCache="true">
<reportElement
x="0"
y="43"
width="468"
height="21"
key="subreport-2"
positionType="Float"/>
<dataSourceExpression><![CDATA[$P{dataSourceConvictionHistory}]]></dataSourceExpression>
<subreportExpression class="java.io.InputStream"><![CDATA[this.getClass().getResourceAsStream("/config/template/subreportConvictionHistory.jasper")]]></subreportExpression>
The subreports themselves are very similarly designed, with all the bands having is isSplitAllowed="true", and they ues the same fonts and the same types of report elements.
If anyone has any ideas why one would split properly and the other not, your help woulb be much appreciated.
We had the same or at least extremely similar problem. The cause wasn't in the report, but in the definition of the subreport. It was configured to have multiple columns and when it reached the last line of the report it startet again on the top in the second column.
Setting it to single column fixed that. The following is the simplified delta in our case
-<jasperReport ... columnCount="3" pageWidth="240" pageHeight="555" ...>
+<jasperReport ... pageWidth="240" pageHeight="555" ...>
Now the band starts on the next page if the subreport doesn't fit on the current page.