我需要使数据集在参数字段上运行,该参数字段是我从Java代码收到的集合。
我正在尝试
<datasetRun subDataset="EstruturaOrganicaDTO" uuid="c3ec8434-efe9-4dbe-8c1a-4ba8be684bda">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($P{EstruturasOrganicas}.getFieldValue( $F{estruturaOrganica}))]]></dataSourceExpression>
</datasetRun>
这是我的报告,只是说他找不到字段
<?xml version="1.0" encoding="UTF-8"?>
<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="objetivo" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6cbf12c5-03fc-4c49-ac33-e581f0aa391f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="EstruturaOrganica" uuid="37e37553-5bbd-4474-aa35-1138420f9b25">
<queryString>
<![CDATA[]]>
</queryString>
<field name="codDivisao" class="java.lang.String"/>
<field name="nomeDivisao" class="java.lang.String"/>
<field name="siglaDivisao" class="java.lang.String"/>
<field name="missao" class="java.lang.String"/>
<field name="visao" class="java.lang.String"/>
</subDataset>
<subDataset name="EstruturaOrganicaDTO" uuid="8cc2ff0b-66f4-4417-bd17-d8d1ed73473a">
<queryString>
<![CDATA[]]>
</queryString>
<field name="estruturaOrganica" class="java.util.Collection"/>
</subDataset>
<subDataset name="Dataset1" uuid="daf8a3e2-f448-4dbe-88ff-e1095ed9337e">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<parameter name="EstruturasOrganicas" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<detail>
<band height="284" splitType="Stretch">
<componentElement>
<reportElement x="100" y="47" width="200" height="200" uuid="78b36e22-df70-4de8-87db-5011ead4bc8a">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="EstruturaOrganicaDTO" uuid="c3ec8434-efe9-4dbe-8c1a-4ba8be684bda">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($P{EstruturasOrganicas}.getFieldValue( $F{estruturaOrganica}))]]></dataSourceExpression>
</datasetRun>
<jr:column width="40" uuid="5dcf02b8-6426-497a-8624-d08f06632a5a">
<jr:tableHeader style="Table_TH" height="30"/>
<jr:tableFooter style="Table_TH" height="30"/>
<jr:columnHeader style="Table_CH" height="30"/>
<jr:columnFooter style="Table_CH" height="30"/>
<jr:detailCell style="Table_TD" height="30"/>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
我要在参数字段中进行迭代。
我正在使用Java
List <EstruturaOrganicaDTO> constatacoes1 = new ArrayList<>();
EstruturaOrganicaDTO estruturaOrganicaDTO = new EstruturaOrganicaDTO();
estruturaOrganicaDTO
.setEstruturaOrganica(
new ArrayList<EstruturaOrganicaEntity>( ));
estruturaOrganicaDTO.getEstruturaOrganica().add(new EstruturaOrganicaEntity("abc", "123",
"fdh", "123", "2456", false));
JRBeanCollectionDataSource beanCollectionDataSource1 = new JRBeanCollectionDataSource(constatacoes1);
final String jasperReportPath = "jasper-templates/objetivo.jrxml";
InputStream inputStreamTemplate = this.environment.resourceAsStream(jasperReportPath);
JasperReport report = JasperCompileManager.compileReport(inputStreamTemplate);
Map<String, Object> parametros = new HashMap<>();
parametros.put("EstruturasOrganicas", beanCollectionDataSource1);
JasperPrint print = JasperFillManager.fillReport(report, parametros, new JREmptyDataSource());
File pdf = File.createTempFile("temp", ".pdf");
pdf.deleteOnExit();
JasperExportManager.exportReportToPdfStream(print, new FileOutputStream(pdf));