简体   繁体   English

JasperReports连接

[英]JasperReports Connection

I'm trying to export my dataTable, for that I'm using JasperReport, but it doesn't work. 我正在尝试导出我的dataTable,因为我正在使用JasperReport,但是它不起作用。 I got this error: 我收到此错误:

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean

Can you help me please. 你能帮我吗。

  <?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" >
<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>
<queryString language="HQL">
    <![CDATA[SELECT
 article.`CODE_ARTICLE` AS article_CODE_ARTICLE,
 article.`DESIGNATIONAL` AS article_DESIGNATIONAL,
 article.`DESIGNATIONFR` AS article_DESIGNATIONFR
FROM
 `article` article]]>
</queryString>
<field name="article_CODE_ARTICLE" class="java.lang.String"/>
<field name="article_DESIGNATIONAL" class="java.lang.String"/>
<field name="article_DESIGNATIONFR" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="136" splitType="Stretch">

        <staticText>
            <reportElement style="Title" x="270" y="0" width="263" height="62"/>
            <textElement verticalAlignment="Middle">
                <font pdfFontName="Times-Roman"/>
            </textElement>
            <text><![CDATA[Articles]]></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" />
            <graphicElement>
                <pen lineWidth="0.5" lineColor="#999999"/>
            </graphicElement>
        </line>
        <staticText>
            <reportElement style="Column header" x="0" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_CODE_ARTICLE]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="267" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_DESIGNATIONAL]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="534" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_DESIGNATIONFR]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="15" splitType="Stretch">
        <frame>
            <reportElement style="Row" mode="Opaque" x="0" y="0" width="802" height="15"/>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="0" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_CODE_ARTICLE}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="267" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_DESIGNATIONAL}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="534" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_DESIGNATIONFR}]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</detail>
<columnFooter>
    <band height="6" splitType="Stretch">
        <line>
            <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="802" height="1" />
            <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" />
            <textField evaluationTime="Report">
                <reportElement style="Column header" x="783" y="1" width="40" height="20" forecolor="#736343" />
                <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" />
                <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"/>
                <textElement verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>

and this is my function: 这是我的功能:

 public void test(){
      JasperReport jasperReport;
JasperPrint jasperPrint;
try
{
  jasperReport = JasperCompileManager.compileReport(
      "C:/soprocess/ExportModel/report1.jrxml");
        JRBeanCollectionDataSource beanColDataSource =
  new JRBeanCollectionDataSource(articleDAO.findAll());
  jasperPrint = JasperFillManager.fillReport(
      jasperReport, new HashMap(),beanColDataSource);
  JasperExportManager.exportReportToPdfFile(
      jasperPrint, "C:/soprocess/ExportModel/simple_report.pdf");
}
catch (JRException e)
{
  e.printStackTrace();
}

The

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean

Is thrown when jasper report can't access a public getter with the name of your field in the bean that you are passing as datasource. 当jasper报告无法使用您作为数据源传递的bean中的字段名称访问公共getter时引发。

You need to have in the bean passed by articleDAO.findAll() method's similar to 您需要在通过articleDAO.findAll()方法传递的bean具有类似于

public String getArticle_CODE_ARTICLE(){//your code}
public String getArticle_DESIGNATIONAL(){//your code}
public String getArticle_DESIGNATIONFR(){//your code}

since you have these fields 因为你有这些领域

<field name="article_CODE_ARTICLE" class="java.lang.String"/>
<field name="article_DESIGNATIONAL" class="java.lang.String"/>
<field name="article_DESIGNATIONFR" class="java.lang.String"/>

Note that: 注意:

<queryString language="HQL">
<![CDATA[SELECT
article.`CODE_ARTICLE` AS article_CODE_ARTICLE,
article.`DESIGNATIONAL` AS article_DESIGNATIONAL,
article.`DESIGNATIONFR` AS article_DESIGNATIONFR
FROM
 `article` article]]>
</queryString>

is not considered since you are passing a JRBeanCollectionDataSource , if you like it to be considered you need to pass the Hibernate Connection instead (along with other configurations for jasper report to understand your mapping) . 因为您正在传递JRBeanCollectionDataSource ,所以不考虑使用,如果您希望将其视为传递,则需要传递Hibernate Connection (以及其他配置(用于jasper报告,以了解您的映射))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM