Java 通过JasperReports中的subreportExpression传递InputStream
我对JasperReports的报告有问题,因为我使用的是Spring启动框架。我需要传递一个InputStream,而不是子报表表达式标记中的绝对路径 因此,我为这个InputStream添加了一个参数:Java 通过JasperReports中的subreportExpression传递InputStream,java,jasper-reports,subreport,Java,Jasper Reports,Subreport,我对JasperReports的报告有问题,因为我使用的是Spring启动框架。我需要传递一个InputStream,而不是子报表表达式标记中的绝对路径 因此,我为这个InputStream添加了一个参数: Map<String, Object> parameters = new HashedMap(); parameters.put("STREAM_SUBREPORT",classLoader.getResource(subreport_filename).openStream()
Map<String, Object> parameters = new HashedMap();
parameters.put("STREAM_SUBREPORT",classLoader.getResource(subreport_filename).openStream());
我试图传递的子报表的定义是
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-04-02T23:37:54 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="submissions_subreport_summary" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="408f425e-96dc-41a9-991e-2208c3c8a120">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="233"/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="756"/>
<parameter name="ItemDataSourceSummary" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<field name="title" class="java.lang.String"/>
<field name="details" class="java.lang.String"/>
<title>
<band height="15">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<staticText>
<reportElement x="2" y="0" width="123" height="12" uuid="782e96a2-5db0-458a-9078-63d470b2e155">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box>
<bottomPen lineWidth="1.0"/>
</box>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Subreport Caption]]></text>
</staticText>
</band>
</title>
<detail>
<band height="35">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="280" height="30" uuid="6f92584d-1738-4d79-b169-2f544152341b"/>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="280" y="0" width="270" height="30" uuid="579b2443-f865-4422-888d-d995ffdfbdc5"/>
<textFieldExpression><![CDATA[$F{details}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我尝试在jrxml中使用follow cast
<subreportExpression><![CDATA[(java.io.InputStream($P{DIR_SUBREPORT_SUBMISSION}))]]></subreportExpression>
欢迎提出任何建议 您应该发布STREAM_SUBREPORT参数的定义。嗨,Alex,在我文章的开头,定义为接收InputStream的参数,即parameters.put(“STREAM_SUBREPORT”,classLoader.getResource(SUBREPORT_filename).openStream());我是说jrxml文件BTW的定义,你试过这篇文章的方法吗:?你的问题在这里解决了:你应该发布STREAM_SUBREPORT参数的定义。嗨,Alex,在我的文章的开头,定义为一个接收输入流的参数,即parameters.put(“STREAM_SUBREPORT”,classLoader.getResource(SUBREPORT_filename).openStream());我的意思是jrxml文件的定义顺便说一句,您是否尝试过这篇文章中的方法:?您的问题在这里解决了:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-04-02T23:37:54 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="submissions_subreport_summary" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="408f425e-96dc-41a9-991e-2208c3c8a120">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="233"/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="756"/>
<parameter name="ItemDataSourceSummary" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<field name="title" class="java.lang.String"/>
<field name="details" class="java.lang.String"/>
<title>
<band height="15">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<staticText>
<reportElement x="2" y="0" width="123" height="12" uuid="782e96a2-5db0-458a-9078-63d470b2e155">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box>
<bottomPen lineWidth="1.0"/>
</box>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Subreport Caption]]></text>
</staticText>
</band>
</title>
<detail>
<band height="35">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="280" height="30" uuid="6f92584d-1738-4d79-b169-2f544152341b"/>
<textFieldExpression><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="280" y="0" width="270" height="30" uuid="579b2443-f865-4422-888d-d995ffdfbdc5"/>
<textFieldExpression><![CDATA[$F{details}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: $P{STREAM_SUBREPORT}
<subreportExpression><![CDATA[(java.io.InputStream($P{DIR_SUBREPORT_SUBMISSION}))]]></subreportExpression>
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. java.io cannot be resolved to a type
value = (java.io.InputStream(((java.lang.String)parameter_STREAM_SUBREPORT.getValue()))); //$JR_EXPR_ID=11$