jasper报告grails

时间:2011-11-10 05:19:44

标签: grails jasper-reports grails-plugin

我使用jasper插件以pdf格式获取报告。我正在尝试使用此示例(http://grails.org/plugin/jasper)获取报告。要获取以下代码使用的pdf格式的特定ID信息。

    <div class="buttons">
                <g:form>
                    <g:hiddenField name="id" value="${userManagementInstance?.id}" />
                    <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </g:form>
            </div>
            <g:jasperReport jasper="use" format="PDF" name="users">
<input type="hidden" name="id" value="${userManagementInstance?.id}" />
</g:jasperReport>

我在show.gsp页面上使用了上面的代码来获取特定的id报告。

 <?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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <style name="pagetitle" isDefault="false" fontName="SansSerif" fontSize="14"/>
    <parameter name="id" isForPrompting="false" class="java.lang.String">
<defaultValueExpression><![CDATA["<parameter error>"]]></defaultValueExpression>

</parameter>

<queryString><![CDATA[select * from user_management where id =$P{id}]]></queryString>
        <field name="id" class="java.lang.String"/>

    <field name="user_id" class="java.lang.String"/>
    <field name="user_name" class="java.lang.String"/>

    <background>
        <band/>
    </background>



    <title>
        <band height="79">
            <staticText>
                <reportElement style="pagetitle" x="0" y="0" width="201" height="46"/>
                <textElement/>
                <text><![CDATA[all]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="35"/>
    </pageHeader>
    <columnHeader>
        <band height="61">
        <staticText>
                <reportElement key="staticText" x="0" y="39" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[id]]></text>
            </staticText>

            <staticText>
                <reportElement key="staticText" x="130" y="39" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[userId]]></text>
            </staticText>
            <staticText>
                <reportElement key="staticText" x="266" y="39" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[userName]]></text>
            </staticText>

        </band>
    </columnHeader>
    <detail>
        <band height="42">
        <textField isBlankWhenNull="false" hyperlinkType="None">
                <reportElement key="textField" x="0" y="15" width="130" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{id}]]></textFieldExpression>
            </textField>

            <textField isBlankWhenNull="false" hyperlinkType="None">
                <reportElement key="textField" x="130" y="15" width="136" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{user_id}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false" hyperlinkType="None">
                <reportElement key="textField" x="266" y="15" width="130" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{user_name}]]></textFieldExpression>
            </textField>

        </band>
    </detail>
    <columnFooter>
        <band height="45"/>
    </columnFooter>
    <pageFooter>
        <band height="54"/>
    </pageFooter>
    <summary>
        <band height="42"/>
    </summary>
</jasperReport>

我在web-apps / report文件夹use.jasper中使用上面的代码。

Error 500: Executing action [index] of controller [org.codehaus.groovy.grails.plugins.jasper.JasperController] in plugin [jasper] caused exception: null
Servlet: grails
URI: /inventoryManagment/grails/jasper.dispatch
Exception Message: invalid stream header: 3C3F786D 
Caused by: invalid stream header: 3C3F786D 
Class: Unknown 
At Line: [-1] 

但是我收到的错误是无效的流标题:3C3F786D。 所以请指导我解决这个问题。

1 个答案:

答案 0 :(得分:1)

看起来您正在使用.jrxml文件引用子报表。但是,您应该使用已编译的版本.jasper。

我希望有效!