jack.musajo Posted December 14, 2017 Share Posted December 14, 2017 Hi :)I'm struggling to find the right way to pass data to a subreport throug JAVA.Could someone help me?This is the snippet of my code and report.I tried to pass a parameter in the Jasper.FIllReport function, but it doesn't work at all..Java code: URL url = new URL(repofileurl); URLConnection connection = url.openConnection(); InputStream reportFile = connection.getInputStream(); JasperReport jasperReport = JasperCompileManager.compileReport(reportFile); if (jrSet.getSubReportFileName() != null) { for (String filename : jrSet.getSubReportFileName()){ String subrepofileurl = REPO_TEMPLATE_URL+filename; URL suburl = new URL(subrepofileurl); URLConnection subconn = suburl.openConnection(); InputStream subtemp = subconn.getInputStream(); JasperReport jasperSubReport = JasperCompileManager.compileReport(subtemp); Collection<Object> testSubData = new ArrayList<>(); testSubData.add(new jasperTest()); JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(testSubData); jrSet.getParameters().put("yourSubList", data); jrSet.getParameters().put("subreportParameter", jasperSubReport); } } JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrSet.getParameters(),jrSet.getDataSource());[/code] Report (subreport part):<subreport> <reportElement x="160" y="4" width="392" height="83" uuid="25651434-2f73-4650-8102-20ad1d7b5e69"/> <subreportParameter name="yourSubList"> <subreportParameterExpression> <![CDATA[$P{yourSubList}]]> </subreportParameterExpression> </subreportParameter> <subreportParameter name="subreportParameter"> <subreportParameterExpression> <![CDATA[$P{subreportParameter}]]> </subreportParameterExpression> </subreportParameter> <subreportExpression> <![CDATA[$P{subreportParameter}]]> </subreportExpression>[/code]SubReport (filed to fill, but I don't know how to link the parameters): <textField> <reportElement x="10" y="6" width="100" height="30" uuid="2ca814dc-d485-41ab-9216-d5b5fbb2082b"/> <textFieldExpression><![CDATA[$P{Parameter1}]]></textFieldExpression> </textField> <textField> <reportElement x="160" y="10" width="100" height="30" uuid="0d13edc1-03b1-4e99-b654-8c463dc07a04"/> <textFieldExpression><![CDATA[$F{partenza}]]></textFieldExpression> </textField>[/code]I will be really grateful if someone could help me (or pointing in the right direction! I googled for weeks...) Link to comment Share on other sites More sharing options...
sanbez Posted December 14, 2017 Share Posted December 14, 2017 Usially subreport expression like this:$P(SUBREPORT_DIR)+"mySubreportName.jasper" You pass $P{subreportParameter} from main report as parameter of subreport (which? it seems it not defined yet). It is very unclear (imho).And what the reason use dynamic subreport name?For exaple myFirstReport.jrxml include executing subreport1.jassperand mySecondReport.jrxml include executing subreport2 and may be subreport3.jasperI can't see the reason use dynamic executing subreport1 in mySecondReport.jrxmlSorry for chaotic answer... but question is chaotic too )))Try use static subreport name in mainReport.jrxmlOne useful link:https://stackoverflow.com/questions/18656016/jasperreports-cant-locate-subreport Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now