Java – my Jasper template does not display text
I'm not sure why if I run my sample template, I can't 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 use ant tasks to run such tests
<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
thank you
Solution
You did not specify a data source, so the reason for the report is empty
You can set the properties of the whennodatatype (when there are no data properties in ireport) report to display the "empty" report
Possible values for this property are:
>No pages: there are no pages in the generated document When trying to load such a document, the viewer may throw an error (whennodatatype = "nopages"). > Blank page: the generated document will contain a blank page (whennodatatype = "blankpage"). > All parts, no details: all report parts except the detail part (band) will appear in the generated document (whennodatatype = "allsectionsnodetail"). > No data part: the generated document contains only one NoData part (band) (whennodatatype = "nodatasection")
If you use the NoData section, you should add this frequency band to the report template (for example, with the help of ireport)
When you use java code like this:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,map,new JREmptyDataSource());
It means that you are passing an empty data source, in other words, you are not passing a data source
If you do not pass the data source and database connection, you can only display the data in the report - pass the data through parameters (or initialize the parameters in the report template)