首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jasper报表列表作为参数

Jasper报表列表作为参数
EN

Stack Overflow用户
提问于 2015-04-07 15:41:44
回答 1查看 7.5K关注 0票数 0

在jasperreport中作为参数发送的呈现列表有问题。我将让java应用程序发送充满数据的列表。我想让贾斯珀提交报告。

代码语言:javascript
复制
<?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类:

贵宾套餐;

公共类用户{

代码语言:javascript
复制
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:Engine.fill.JRFillBand.fill(JRFillBand.java:377)java:997)在net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)中,具有较高的适配性,较高的适配性,较高的价格性,较高的价格。Fill.JRFillDataset.setOldValues(JRFillDataset.java:1317).class=‘class 10’类上的匿名性‘公司’PropertyUtils.getProperty(PropertyUtils.java:426)

据贾斯珀报道,vip.User正在努力寻找这一领域。当我使用提示符为false时,它可以工作,使用用数组列表填充的defaultValueExpression。

EN

回答 1

Stack Overflow用户

发布于 2015-04-08 11:53:31

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

如果没有特别的理由。那就跟着这个,

代码语言:javascript
复制
Map parameters = new HashMap();
JasperPrint jasperPrint = null;
jasperPrint  = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(yourList));

并将用户bean类作为Java数据源添加到Jrxml文件中。关于更多的点击

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29495567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档