如何解决jasperreport参数问题

时间:2016-09-30 12:04:54

标签: java jasper-reports

我已经尝试过类似问题的解决方案,但它没有解决我的问题。我想从jcombobox传递一个值作为搜索参数,但是当我提交搜索时,它返回一个空的查看器。以下是一些代码: jrxml:

<?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="null" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d851568a-8c70-49e4-aec7-d04008ad3725">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="Title" fontName="Times New Roman" fontSize="50" isBold="true" pdfFontName="Times-Bold"/>
<style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Arial" fontSize="12"/>
<style name="Row" mode="Transparent">
    <conditionalStyle>
        <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
        <style backcolor="#E6DAC3"/>
    </conditionalStyle>
</style>
<parameter name="session" class="java.lang.String">
    <parameterDescription><![CDATA[]]></parameterDescription>
</parameter>
<queryString language="SQL">
    <![CDATA[SELECT
 employeedata.`fname` AS 'FIRST NAME(S)',
 employeedata.`lname` AS 'LAST NAME',
 employeedata.`gender` AS GENDER,
 employeedata.`empid` AS 'TRAINEE ID',
 logdata.`timein` AS 'TIME IN',
 logdata.`timeout` AS 'TIME OUT',
 logdata.`date` AS DATE
FROM
 `employeedata` employeedata INNER JOIN `fingerdata` fingerdata ON  employeedata.`empid` = fingerdata.`empid`
 INNER JOIN `logdata` logdata ON fingerdata.`fingerid` = logdata.`fingerid` WHERE logdata.session LIKE '$P{session}']]>
</queryString>
<field name="TRAINEE ID" class="java.lang.String"/>
<field name="FIRST NAME(S)" class="java.lang.String"/>
<field name="LAST NAME" class="java.lang.String"/>
<field name="GENDER" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="TIME IN" class="java.lang.String"/>
<field name="TIME OUT" class="java.lang.String"/>
<field name="DATE" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="DATE">
    <groupExpression><![CDATA[$F{DATE}]]></groupExpression>
    <groupHeader>
        <band height="7"/>
    </groupHeader>
    <groupFooter>
        <band height="17"/>
    </groupFooter>
</group>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="129" splitType="Stretch">
        <staticText>
            <reportElement style="Title" x="12" y="0" width="608" height="62" uuid="c0820f28-affb-498f-b54b-01227a0284cc"/>
            <textElement verticalAlignment="Middle">
                <font pdfFontName="Times-Roman"/>
            </textElement>
            <text><![CDATA[TRAINEE ATTENDANCE]]></text>
        </staticText>
        <staticText>
            <reportElement style="SubTitle" x="144" y="62" width="322" height="22" uuid="e0359ffb-478d-4de6-a82a-66515635d2fb"/>
            <textElement>
                <font fontName="Times New Roman" pdfFontName="Times-Roman"/>
            </textElement>
            <text><![CDATA[GRADUATE ASSISTANCE PROGRAM]]></text>
        </staticText>
    </band>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="16" splitType="Stretch">
        <line>
            <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="802" height="1" uuid="6db14758-77dd-4844-bad9-7d698c3ffad5"/>
            <graphicElement>
                <pen lineWidth="0.5" lineColor="#999999"/>
            </graphicElement>
        </line>
        <staticText>
            <reportElement style="Column header" x="0" y="0" width="133" height="15" forecolor="#736343" uuid="f72ba507-10a9-4fd4-a5ad-68a33fe89126"/>
            <text><![CDATA[TRAINEE ID]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="133" y="0" width="133" height="15" forecolor="#736343" uuid="5a02d9cf-5b0e-41e1-998f-8e44e7b93e13"/>
            <text><![CDATA[FIRST NAME]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="266" y="0" width="133" height="15" forecolor="#736343" uuid="155032b8-2c4f-4cd6-82c7-abb9f0263ff5"/>
            <text><![CDATA[LAST NAME]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="399" y="0" width="133" height="15" forecolor="#736343" uuid="f68c1322-406d-481d-84c1-b3a70a03499a"/>
            <text><![CDATA[GENDER]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="532" y="0" width="133" height="15" forecolor="#736343" uuid="e4a8997b-27e0-4aab-abd6-15b2a09f5026"/>
            <text><![CDATA[TIME IN]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="665" y="0" width="133" height="15" forecolor="#736343" uuid="5d27501b-9a40-4a9a-a6c1-de8a76a7c28b"/>
            <text><![CDATA[TIME OUT]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="15" splitType="Stretch">
        <frame>
            <reportElement style="Row" mode="Opaque" x="0" y="0" width="802" height="15" uuid="396a2ef1-a55d-4e7f-96f7-d59306ef4dc6"/>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="0" y="0" width="133" height="15" uuid="f91b07d1-9414-406a-bb05-ead75d9e0085"/>
                <textFieldExpression><![CDATA[$F{TRAINEE ID}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="133" y="0" width="133" height="15" uuid="4cb43463-0bf8-4fb3-9d52-0e9169b308db"/>
                <textFieldExpression><![CDATA[$F{FIRST NAME(S)}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="266" y="0" width="133" height="15" uuid="f1f8f2f0-931e-4a5f-95ac-bb9e111d76eb"/>
                <textFieldExpression><![CDATA[$F{LAST NAME}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="399" y="0" width="133" height="15" uuid="815e7600-2229-4a29-ad65-bcb4245a51f5"/>
                <textFieldExpression><![CDATA[$F{GENDER}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="532" y="0" width="133" height="15" uuid="ba5758f3-557e-41ec-bdf6-1a13ea151a16"/>
                <textFieldExpression><![CDATA[$F{TIME IN}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="665" y="0" width="133" height="15" uuid="207195ad-0f32-49bf-b137-3ac636fb71b0"/>
                <textFieldExpression><![CDATA[$F{TIME OUT}]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</detail>
<columnFooter>
    <band height="6" splitType="Stretch">
        <line>
            <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="802" height="1" uuid="18f13873-aacf-49ea-9a7e-dc8f9ef726d6"/>
            <graphicElement>
                <pen lineWidth="0.5" lineColor="#999999"/>
            </graphicElement>
        </line>
    </band>
</columnFooter>
<pageFooter>
    <band height="25" splitType="Stretch">
        <frame>
            <reportElement mode="Opaque" x="-21" y="1" width="843" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" uuid="2daa1b9a-87d3-4154-b8eb-beacdc8b019a"/>
            <textField evaluationTime="Report">
                <reportElement style="Column header" x="783" y="1" width="40" height="20" forecolor="#736343" uuid="48733e5a-d35c-44b6-9607-1419ce88368e"/>
                <textElement verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="Column header" x="703" y="1" width="80" height="20" forecolor="#736343" uuid="060b07c0-5c84-46ac-9897-26b2a1201be7"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField pattern="EEEEE dd MMMMM yyyy">
                <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343" uuid="42492e3f-1a41-4ef9-98e2-24028728877a"/>
                <textElement verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</pageFooter>
<summary>
    <band height="63" splitType="Stretch">
        <staticText>
            <reportElement x="21" y="29" width="138" height="20" uuid="a6a0595a-3d06-4ca9-8eaa-c15350637112"/>
            <text><![CDATA[NUMBER OF RECORDS]]></text>
        </staticText>
        <textField>
            <reportElement x="166" y="29" width="100" height="20" uuid="42bfc9b3-e432-4b00-adc1-9aae2372f71f"/>
            <textFieldExpression><![CDATA[$V{DATE_COUNT}]]></textFieldExpression>
        </textField>
    </band>
</summary>

方法:

public void printPDFReport(String session) throws Exception {
    try {

        Class.forName("com.mysql.jdbc.Driver");
        Connection connex = DriverManager.getConnection("jdbc:mysql://localhost/placess_dbase", "root", "");
        HashMap parameter = new HashMap<>();
        parameter.put("session", session.toUpperCase());

        String report = "C:\\users\\lami\\desktop\\placess_src\\placess\\src\\reports\\allStaffAttendance.jrxml";
        JasperReport jr = JasperCompileManager.compileReport(report);
        JasperPrint jp = JasperFillManager.fillReport(jr, parameter, connex);
        JasperExportManager.exportReportToPdfFile(jp, "c:/output/attendance.pdf");
        URL url = new URL("file:c:/output/attendance.pdf");
        JasperViewer jv = new JasperViewer(jp, false);

        jv.setVisible(true);

    } catch (Exception e) {

    }

}

调用方法的客户端代码段:

if (jrbAll.isSelected() && session!=null) {


        try {
            FReport fr = new FReport();
            fr.printPDFReport(jcbSession.getSelectedItem().toString());
        } catch (Exception exception) {

            exception.printStackTrace();
        }

    }
请帮助......已经令人沮丧了。我使用了ireport 5.6和netbeans谢谢

0 个答案:

没有答案