当前位置: 首页 > 知识库问答 >
问题:

Jasper报告列表为参数

吕永寿
2023-03-14
<?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>
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;
}

Jasper reports正在努力从vip.user中找到字段。当我将prompt作为false使用defaultValueExpression填充数组列表时,它可以工作。

共有1个答案

养焱
2023-03-14

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

如果没有特别的原因。那么就应该遵循这个,

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

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

 类似资料:
  • 我正在从. jasper文件加载jasper报告文件以提高性能,如下所示。 但是我现在有一个要求,动态形成的查询必须设置为. jasper(编译)文件。有没有办法做同样的事情?

  • 我想生成jasper报表,用于打印在固定大小的文具上。我创建了html表,并将所有的值放在其中,根据我的要求,现在我想通过Java打印,所以我现在使用了jasper报告,因为我有列,是变化的时间。根据我的要求,我在网上搜索,我得到了动态的jasper是解决方案,但由于方法添加列需要列名和传递变量,这是从setter getter方法,但我的整个列是动态的,那么我如何生成setter getter方

  • 我已经使用JRResultSetDataSource使用了Jasper报告,但这是我第一次使用JRBeanGrou 我正在尝试使用以下代码运行报告测试: 客户.java Report.java clientereport.jrxml Main.java 我得到以下错误: 我不知道我的代码有什么问题。

  • 我试图做一个Jasper报表簿,稍后填充它的内容,并保持封面不变,但是当我使用与报表簿对应的. jasper时,我得到了一个空白页。我一个接一个地传递这本书的页面,它起作用了,但是当我传递整本书时,我什么也没得到。 有人知道如何在java中使用整个Jasper报告簿来生成PDF吗? 谢谢。

  • 我将使用jasper reports生成报告。为此,我的计划是, 使用iReport工具根据需要创建jrxml文件 从报告外部设置所需的值。(我的意思是,如果我在java程序中有一个名为james的变量,请将该变量设置为报告中的文本字段) 然后创建报告并生成pdf 我需要知道的是这种可能性。我可以将变量设置到jrxml文件的字段中吗?如果可能的话,我怎么做?

  • 我用的是Jasper reports 6.17,我在Jasper Studio里做了一个列表。 列表中只有两个名为“test1”和“test2”的项目,但只显示了一个,我不知道为什么。生成的PDF仅显示“test2”,为什么缺少“test1”?如果我添加10项,第一行将丢失。 jrxml文件是: java文件是: