繁体   English   中英

Jasper报告列表作为参数

[英]Jasper reports List as Parameter

我在jasperreport中将渲染列表作为参数发送时遇到问题。 我将让Java应用程序发送充满数据的列表。 我想让Jasper呈现报告。

<?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="r1_10_002_active_agent_invol_jrxml_1275409438288" pageWidth="1040" pageHeight="792" orientation="Landscape" whenNoDataType="NoDataSection" columnWidth="1032" leftMargin="4" rightMargin="4" topMargin="20" bottomMargin="20" uuid="ac26d847-4888-412d-832a-29f36daa0c69">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.jasperserver.reportUnit" value="/reports/Test/Test"/>
    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver/services/repository"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <style name="column_header" mode="Opaque" forecolor="#000000" backcolor="#F1E5D4" hAlign="Center" vAlign="Bottom" fontName="Arial">
        <box bottomPadding="2">
            <pen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFFFF"/>
        </box>
    </style>
    <style name="alternate_row" mode="Opaque" forecolor="#000000" backcolor="#FFFFFF" hAlign="Left" vAlign="Middle" fontName="Arial">
        <box leftPadding="2" rightPadding="2">
            <pen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        </box>
    </style>
    <style name="title_2" isDefault="true" mode="Opaque" forecolor="#000000" backcolor="#FFFFFF" hAlign="Left" vAlign="Middle" fontName="Arial" fontSize="11" isBold="true">
        <box leftPadding="4" rightPadding="2"/>
    </style>
    <style name="default_text" isDefault="true" mode="Opaque" forecolor="#000000" backcolor="#FFFFFF" hAlign="Left" vAlign="Middle" fontName="Arial">
        <box leftPadding="2" rightPadding="2"/>
    </style>
    <style name="column_header_sorted" mode="Opaque" forecolor="#000000" backcolor="#958671" hAlign="Center" vAlign="Bottom" fontName="Arial" fontSize="11" isBold="false">
        <box bottomPadding="2">
            <pen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        </box>
    </style>
    <style name="title" mode="Opaque" forecolor="#000000" backcolor="#FFFFFF" hAlign="Left" vAlign="Top" fontName="Arial" fontSize="24" isBold="true">
        <box topPadding="2" leftPadding="4"/>
    </style>
    <style name="group_section" mode="Opaque" forecolor="#000000" backcolor="#D3CAB7" hAlign="Left" vAlign="Middle" fontName="Arial" fontSize="12" isBold="false">
        <box leftPadding="2" rightPadding="2">
            <pen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        </box>
    </style>
    <style name="group2_section" mode="Opaque" forecolor="#6B542E" backcolor="#FFFFFF" hAlign="Left" vAlign="Middle" fontName="Arial" fontSize="11" isBold="true" isItalic="false">
        <box leftPadding="2" rightPadding="2">
            <pen lineWidth="0.0" lineStyle="Dashed" lineColor="#FFFFFF"/>
            <topPen lineWidth="0.0" lineStyle="Dashed" lineColor="#FFFFFF"/>
            <leftPen lineWidth="0.0" lineStyle="Dashed" lineColor="#FFFFFF"/>
            <bottomPen lineWidth="0.0" lineStyle="Dashed" lineColor="#FFFFFF"/>
            <rightPen lineWidth="0.0" lineStyle="Dashed" lineColor="#FFFFFF"/>
        </box>
    </style>
    <style name="section" mode="Opaque" forecolor="#000000" backcolor="#999999" hAlign="Left" vAlign="Middle" fontName="Arial" fontSize="12">
        <box leftPadding="2" rightPadding="2"/>
    </style>
    <subDataset name="dataset3" uuid="24fb1a54-d444-461e-ac5e-7343f728ee8c">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="company" class="java.lang.String"/>
    </subDataset>
    <parameter name="environment" class="java.lang.String"/>
    <parameter name="username" class="java.lang.String"/>
    <parameter name="show_header" class="java.lang.String"/>
    <parameter name="users" class="java.util.Collection">
        <defaultValueExpression><![CDATA[java.util.Arrays.asList( new vip.User("Agent 1"), new vip.User("Agent 2") )]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[select 1 from dual]]>
    </queryString>
    <field name="id" class="java.lang.Integer"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="58" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($P{show_header}.equals("1"))]]></printWhenExpression>
            <staticText>
                <reportElement uuid="a9d04c94-435d-4baf-9d72-7321d7389aa8" key="staticText-8" style="title" x="194" y="0" width="838" height="33"/>
                <box topPadding="2" leftPadding="4">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <text><![CDATA[Active Agent Involuntary Fee]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="c203c163-7092-44d7-86d9-a74572a5c4f8" key="staticText-16" style="title_2" x="194" y="40" width="112" height="15"/>
                <box leftPadding="4" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <text><![CDATA[Environment: ]]></text>
            </staticText>
            <textField isBlankWhenNull="false">
                <reportElement uuid="e586fc32-d009-4996-97b8-f8931501fe83" key="textField-49" style="default_text" x="306" y="40" width="246" height="15"/>
                <box leftPadding="2" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{environment}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement uuid="e5313ccd-3c5a-4dfd-a2bc-dc9663f6ca16" key="staticText-17" style="title_2" x="552" y="40" width="112" height="15"/>
                <box leftPadding="4" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <text><![CDATA[User: ]]></text>
            </staticText>
            <textField isBlankWhenNull="false">
                <reportElement uuid="26bb86f6-7bfc-4afc-aee2-6a064197387f" key="textField-50" style="default_text" x="664" y="40" width="251" height="15"/>
                <box leftPadding="2" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$P{username}]]></textFieldExpression>
            </textField>
            <image scaleImage="RetainShape">
                <reportElement uuid="e34dbb4b-ca15-4e88-9f91-657e20fc09c7" key="image-1" style="default_text" x="7" y="6" width="177" height="44"/>
                <imageExpression><![CDATA["repo:/PAR/VIPR/Images/Logo_BW.gif"]]></imageExpression>
            </image>
        </band>
    </title>
    <pageHeader>
        <band height="32" splitType="Stretch">
            <textField isBlankWhenNull="false">
                <reportElement uuid="9d71a482-e52e-4fc8-8455-4bc6d834af73" key="textField-3" style="column_header_sorted" x="552" y="0" width="63" height="20"/>
                <box bottomPadding="2">
                    <pen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center"/>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="200" splitType="Prevent">
            <staticText>
                <reportElement uuid="8d2b2a61-53bc-4d25-be40-e984af9555e5" x="270" y="0" width="200" height="15"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Bean with List sample]]></text>
            </staticText>
            <componentElement>
                <reportElement uuid="c5f0d6ad-400c-4ae8-acdc-92ea0b43a003" x="270" y="0" width="200" height="15"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="dataset3" uuid="ec5dd79d-3f64-46d2-b4fa-b6c05abbe86a">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{users})]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="15" width="222">
                        <textField>
                            <reportElement uuid="a9e856e2-9749-4d94-9a46-55384fd1b524" x="100" y="0" width="100" height="15"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{company}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="15" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($P{show_header}.equals("1"))]]></printWhenExpression>
            <textField isBlankWhenNull="false">
                <reportElement uuid="947b6598-b833-41f9-a95b-3496207f0aeb" key="textField-33" style="default_text" x="0" y="0" width="558" height="15"/>
                <box leftPadding="2" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA["Date Printed: " + new Date().toLocaleString()]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement uuid="6575ad0c-1884-4c8d-adef-ed28e0753d42" key="textField-37" style="default_text" x="558" y="0" width="444" height="15"/>
                <box leftPadding="2" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page " + $V{PAGE_NUMBER}.toString() + " of "]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report" isBlankWhenNull="false">
                <reportElement uuid="0d67d248-a477-4c81-8a34-845cb2f7b4e6" key="textField-38" style="default_text" x="1002" y="0" width="30" height="15"/>
                <box leftPadding="2" rightPadding="2">
                    <pen lineWidth="0.0"/>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="0.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="0.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>

Java类:

包装贵宾;

公共类用户{

private String company;
private String companyType;
private String eecdId;
private String firstName;
private String lastName;
private String email;
private String userId;
private String status;

public User(String company) {
    super();
    this.company = company;
}
public String getEecdId() {
    return eecdId;
}
public void setEecdId(final String eecdId) {
    this.eecdId = eecdId;
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(final String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(final String lastName) {
    this.lastName = lastName;
}
public String getEmail() {
    return email;
}
public void setEmail(final String email) {
    this.email = email;
}
public void setCompany(final String company) {
    this.company = company;
}
public String getCompany() {
    return company;
}
public void setCompanyType(final String companyType) {
    this.companyType = companyType;
}
public String getCompanyType() {
    return companyType;
}
public void setUserId(final String userId) {
    this.userId = userId;
}
public String getUserId() {
    return userId;
}
public void setStatus(final String status) {
    this.status = status;
}
public String getStatus() {
    return status;
}

}

但是在尝试访问JRXML中的现场公司时,我遇到了错误。

net.sf.jasperreports.engine.JRRuntimeException:net.sf.jasperreports.engine.JRException:从bean检索字段值时出错:位于net.sf.jasperreports.components.list.VerticalFillList.prepare(VerticalFillList.java:139)的公司位于net.sf.jasperreports.engine的net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:328)处的net.sf.jasperreports.engine.fill.JRFillComponentElement.java:129)在net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.fill(JRFillBand.java:351)在net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller。 net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:771)处的net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:281)处的Java:2039) .jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:14 4)位于net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.fill(JRBaseFiller.java:841)处的net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.fill(JRBaseFiller.java:841)处位于net.sf.jasperreports net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)上的.engine.fill.JRFiller.fill(JRFiller.java:88),net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java) :569),位于org.openide.util的com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:928)的net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:915)上。 org.openide.util.RequestProcessor $ Processor.run(RequestProcessor.java:997)处的RequestProcessor $ Task.run(RequestProcessor.java:572)原因:net.sf.jasperreports.engine.JRException:从bean检索字段值时出错:位于net.sf.jas的net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)的公司 位于net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)的perreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)位于net.sf.jasperreports.engine.fill.JRFillDataset。 net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1218)的setOldValues(JRFillDataset.java:1317)at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1194)在net.sf.jasperreports.components.list.FillDatasetRun.next(FillDatasetRun.java:168)在net.sf.jasperreports.components.list.VerticalFillList.prepare(VerticalFillList.java:97)...更多17位原因: java.lang.NoSuchMethodException:org.apache.commons.beanutils.PropertyUtilsBean上的org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1322)上的类'class java.lang.String'上的未知属性'company' .getNestedProperty(PropertyUtilsBean.java:770)位于或 org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)上的g.apache.commons.beanutils.PropertyUtilsBean.java:846)位于net.sf.jasperreports.engineDatadata.JRBean getBeanProperty(JRAbstractBeanDataSource.java:111)...还有24个

Jasper报告正在努力从vip.User查找字段。 当我使用提示符为false时,使用使用数组列表填充的defaultValueExpression可以工作。

为什么需要将列表发送为参数?

如果没有特殊原因。 然后应该遵循这个

Map parameters = new HashMap();
JasperPrint jasperPrint = null;
jasperPrint  = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(yourList));

并且还将您的User bean类添加为Jrxml文件中的Java Beans数据源。 更多点击

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM