我正在尝试使用XML文档作为数据源来获取报表的子报表。
当我对主报表数据进行排序时,子报表不必重新查询XML文档。它期待 JRSortableDataSource ,而不是 JRXmlDataSource 。
我做错了什么?
我使用了以下数据源表达式:
$P{REPORT_DATA_SOURCE}).subDataSource("/person/phone")
堆栈跟踪:
Error filling print... Error evaluating expression : Source text : $P{REPORT_DATA_SOURCE}.subDataSource("/person/phone")
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
Source text : $P{REPORT_DATA_SOURCE}.subDataSource("/person/phone")
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:966)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:384)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:286)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:459)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2044)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:126)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:300)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:757)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:1003)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: groovy.lang.MissingMethodException:
No signature of method: net.sf.jasperreports.engine.fill.SortedDataSource.subDataSource()
is applicable for argument types: (java.lang.String) values: [/person/phone]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at TestParam_1362739351228_895383.evaluate(calculator_TestParam_1362739351228_895383:223)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
答案 0 :(得分:1)
您的数据源表达式$P{REPORT_DATA_SOURCE}).subDataSource("/B/C")
语法错误有
你最初错过了无与伦比的性格(
然后
如果它期待JRSortableDataSource
使用此表达式
((net.sf.jasperreports.engine.data.JRSortableDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("DefineThat")
如果它期待JRXmlDataSource
使用此表达式
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("DefineThat")
答案 1 :(得分:0)
$ P {REPORT_DATA_SOURCE})。subDataSource( “Xpath的”)
当有人使用上面的表达式连接到使用XML数据源在Jasper中创建子报表时,我们需要将报表语言设置为groovy而不是Java。我认为subdatasource不是Java中定义的方法,而是groovy。我是试图找到一个与Java相同的方法
答案 2 :(得分:0)
遇到同样的问题,请在jaspersoft-community找到此解决方案:
使用参数捕获原始数据源:
<parameter name="MyDataSource" class="net.sf.jasperreports.engine.JRDataSource" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></defaultValueExpression>
</parameter>
在iReport-GUI中相同:
现在在subreport-datasource上使用MyDataSource参数:
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{MyDataSource}).dataSource("/Subreport/path")]]></dataSourceExpression>