cbrownmacquarietelecom.co Posted March 10, 2016 Share Posted March 10, 2016 Hi, I have used the JFreeChartScriptlet to generate a chart that uses the XYZDataset. For testing I've hardcoded the datasource (an XML file) but I need to hook the scriptlet up the report's datasource which is the content of a webservice response. Due to the number of data points it is impracticle to access the chart data via a number of fields. The $V{Chart} is in a subreport; the subreport's data source expression is: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//data")[/code] In the scriptlet I'm trying to access the data source as follows: JRXmlDataSource xmlDataSource = (JRXmlDataSource) this.getParameterValue(JRFillParameter.REPORT_DATA_SOURCE);[/code] When I preview the report I get the following exception: net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//data") at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:524) at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$20(ReportControler.java:499) at com.jaspersoft.studio.editor.preview.view.control.ReportControler$5.run(ReportControler.java:380) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//data") at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:291) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:618) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:586) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1020) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:460) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:351) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:281) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:504) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2026) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:752) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:259) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:119) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:558) at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:119) at java.lang.Thread.run(Thread.java:745) Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'net.sf.jasperreports.engine.JREmptyDataSource@38c38f20' with class 'net.sf.jasperreports.engine.JREmptyDataSource' to class 'net.sf.jasperreports.engine.data.JRXmlDataSource' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599) at JFreeChartReport_1457576688536_715654.evaluate(calculator_JFreeChartReport_1457576688536_715654:304) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:277) ... 14 more How do I reference an external data source from within a scriptlet? Link to comment Share on other sites More sharing options...
ibad.rahman Posted April 15, 2016 Share Posted April 15, 2016 I am getting the exact same error, as far as I can tell. I don't know if scriptlets are involved though. I have some reports that work fine in iReports but produce errors in JasperSoft Studio. Hope someone can help with this issue. Link to comment Share on other sites More sharing options...
cbrownmacquarietelecom.co Posted April 18, 2016 Author Share Posted April 18, 2016 Hi,I managed to get my report working eventually (using the settings given in my original query).I have a report book component for which the data source expression uses net.sf.jasperreports.engine.JREmptyDataSource; I think my scriptlet erroneously referenced this data source (hence the error "Cannot cast object 'net.sf.jasperreports.engine.JREmptyDataSource ..."). To fix this I introduced an intermediate sub-report in which I defined the data source I needed to use in the scriptlet, then, eventually, called a sub-report with the appropriate Scriplet class set.I hope this is useful.CheersChris 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