Why Jasper Reports shows empty report in server, but generates correctly in jasper studio

拟墨画扇 提交于 2019-12-02 07:22:10

If you want to show something in the JasperReport without data source or with empty data source then you have two options:

1) Set the When No Data Type property on All Section No Detail option in the Jasper Studio:

In JRXML it can be done by setting whenNoDataType="AllSectionsNoDetail" attribute on the root <jasperReport> element.

2) Or you can move content you want to show when there is no data into No Data band of the report:

In JRXML it it can be done by adding of this:

<noData>
    <band height="110">
        <image>
            <reportElement x="0" y="0" width="240" height="110" uuid="d4b9e59b-896e-4881-92a2-c6707c975312"/>
            <imageExpression><![CDATA["https://my.image.url/getImage?name=penguin"]]></imageExpression>
        </image>
    </band>
</noData>

JasperReport renders blank page when there are no data as a default and JasperServer shows The report is empty, so select from above options one you prefer to be able to show the image you want.

The best way to do not have the empty page when no data source is provided, is to trick jasper to think there is a data source:

1) Define an Data Adapter (a simple .xml file) and put it in reports folder:

<?xml version="1.0" encoding="UTF-8" ?><emptyDataAdapter class="net.sf.jasperreports.data.empty.EmptyDataAdapterImpl"><name>Data Adapter fake</name><recordCount>1</recordCount></emptyDataAdapter>

2) Link it into the main report:

<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="repor" language="javascript" pageWidth="612" pageHeight="792" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="c0eee90e-1b1a-4f34-ad99-1112847752de">
<property name="net.sf.jasperreports.data.adapter" value="EmptyDataAdapter.xml"/>

prefix "repo:" to the value of the property for the data adapter, if the xml is deployed on jasper server.

The attribute "whenNoDataType" will be ignored.

Other details here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!