0

这可能是一个棘手的问题。

使用 jaspersoft studio 我创建了一个报告:myreport.jrxml,它工作得很好:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="Blank A4" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="36f7dbef-85e9-4a2e-bc9a-61e146a441b6">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="ISA"/>
    <queryString>
        <![CDATA[select nom, prenom from beneficiaire where nni='105011411873713']]>
    </queryString>
    <field name="NOM" class="java.lang.String"/>
    <field name="PRENOM" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <pageHeader>
        <band height="147" splitType="Stretch">
            <image>
                <reportElement uuid="ca704754-4477-48ed-999d-29bc717e08d3" x="0" y="0" width="50" height="50"/>
                <imageExpression><![CDATA["C:/Documents and Settings/DAVENNE-09298/Bureau/logo_assurance_maladie.gif"]]></imageExpression>
            </image>
            <staticText>
                <reportElement uuid="29581e3a-a202-43c1-b3c9-47a56d05edfe" x="0" y="60" width="121" height="25"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <text><![CDATA[SERVICE  ADMINISTRATIF
DU CENTRE APPAREILLAGE]]></text>
            </staticText>
            <textField>
                <reportElement uuid="7049158d-a7e1-4c10-adb0-2e10e11bbcb7" x="380" y="80" width="175" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{NOM} + ' ' + $F{PRENOM}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="253" splitType="Stretch">
            <staticText>
                <reportElement uuid="c6bb6b7e-5316-49fb-b3c4-90faed1f4fcc" x="3" y="15" width="552" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[A L'ATTENTION DE VOTRE MUTUELLE]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="c3e93907-b312-437f-b032-68c919387986" x="0" y="50" width="554" height="130"/>
                <textElement/>
                <text><![CDATA[Madame, Monsieur,

La fourniture ....

Le montant ...

Recevez, Madame, Monsieur, mes sincères salutations]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="f71b41b6-02fb-44d4-9c8d-f10cc78d4b83" x="370" y="200" width="186" height="51"/>
                <textElement/>
                <text><![CDATA[LE RESPONSABLE DU SERVICE

]]></text>
            </staticText>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
</jasperReport>

现在我想在我的 struts 2 项目中使用这个模板(我在我的项目中添加了 struts2-jasperreport 插件)。我必须添加 myreport.jasper 但在我摆脱项目中不需要的 2 行之前:

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="ISA"/>
<queryString>
        <![CDATA[select nom, prenom from beneficiaire where nni='105011411873713']]>
</queryString>

我声明我的新结果类型:

<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>

我在 struts.xml 中声明我的操作:

<action name="testCourrierMutuellePDF" class="isa.presentation.jasper.CourrierMutuellePDF">
    <result name="success" type="jasper">
        <param name="location">jasper/courriers/myreport.jasper</param>
        <param name="dataSource">resultats</param>
        <param name="format">PDF</param>
    </result>
 </action>

我写了我的动作课:

private Beneficiaire resultats;

public String execute() {
        try {
            GestionBeneficiaireFacade facade = GestionBeneficiaireFacade.getInstance();
            resultats = facade.recupererBeneficiaire("105011411873713");
        } catch (IsaException e) {
            this.addActionMessage(this
                    .getText("error.benefInfosAction.sauverBenef"));
            this.isaException = e;
            return ERROR;
        }
        return SUCCESS;
    }

public Beneficiaire getResultats() {
        return this.resultats;
}

我确信几件事:

  1. 找到jasper文件是因为我没有FileNotFoundException

  2. 找到数据源是因为我调试了,调用了getter,不为空,数据在里面

最后一件事..当然,我的对象结果具有“nom”和“prenom”属性

无论如何,我得到一个我不明白的 nullpointerException :

java.lang.NullPointerException
    net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
    net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
    org.apache.struts2.views.jasperreports.JasperReportsResult.doExecute(JasperReportsResult.java:326)
    org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
    isa.presentation.intercepteur.IsaExceptionXMLIntercepteur.intercept(IsaExceptionXMLIntercepteur.java:29)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:251)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

感谢 Aleksandr,我升级了 jasperReport 库,并且有了我的 pdf 文件。但是名称和名字为空。当我调试应用程序时,我可以看到通过 getter 调用 resultats 变量,并且 name / firstname 属性不为空,但具有良好的值..

所以?任何想法 ?

4

1 回答 1

0

当然是区分大小写的

所以不是 NOM 和 PRENOM 而是 nom 和 prenom

于 2012-12-13T11:51:02.043 回答