Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

java - My Jasper Template shows no text

I am currently unsure why if I ran this sample template of mine, I cannot see any text.

<?xml version="1.0"?>
<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="SampleReport" pageWidth="798" pageHeight="1000">
    <title>
        <band height="50">
          <staticText>
            <reportElement x="0" y="0" width="180" height="15"/>
            <textElement/>
            <text>
              <![CDATA[Sample Title]]>
            </text>
          </staticText>
        </band>
      </title>
    <detail>
        <band height="20">
            <staticText>
                <reportElement x="20" y="0" width="200" height="20"/>
                <text>
                    <![CDATA[Sample Text]]>
                </text>
            </staticText>
        </band>
    </detail>
</jasperReport>

I used ant task to run this test like this.

<target name="viewDesignXML"
    <java classname="net.sf.jasperreports.view.JasperDesignViewer"
        fork="true">
        <arg value="-XML" />
        <arg value="-F${file.name}.jrxml" />
        <classpath refid="classpath" />
    </java>
</target>

This is Jasperreport 4.5 with eclipse 3.6

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You did not specify the datasource and so the cause of your report is empty.

You can set whenNoDataType (When No Data property in iReport) report's attribute for showing "empty" report.

The possible values of this attribute are:

  • No Pages: The generated document will have no pages in it. Viewers might throw an error when trying to load such documents (whenNoDataType="NoPages").
  • Blank Page: The generated document will contain a single blank page (whenNoDataType="BlankPage").
  • All Sections, No Detail: All the report sections except the Detail section (band) will appear in the generated document (whenNoDataType="AllSectionsNoDetail").
  • No Data Section: The generated document will contain only a single noData section (band) (whenNoDataType="NoDataSection").

In case using noData section you should add this band to the report's template (for example, with help of iReport).


When you are using the Java code like this:

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
       map, new JREmptyDataSource());

it means that you are passing the empty datasource or in other words did not pass the datasource.

In case you did not pass datasource and database connection the only chance to show the data at report - is to pass data via parameters (or initialize parameters inside the report's template)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...