My Jasper Template shows no text
eclipse, jasper-reports, java
Solution
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)
Problem
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