JasperReports renders empty pdf - java

I'm just doing a test, i want to print some static text yet it doesn't save pdf.
<?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="FirstReport">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20" />
<text>
<![CDATA[If you don't see this, it didn't work]]>
</text>
</staticText>
</band>
</detail>
</jasperReport>
The code is:
public class PDF {
public void genereazaRaport() {
try {
InputStream input = new FileInputStream(new File("jrxml/test.jrxml"));
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
//Map<String, Object> parameters = new HashMap<String, Object>();
//parameters.put("Titlu Raport", "PDF JasperReport");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JREmptyDataSource());
OutputStream out = new FileOutputStream(new File("raport/raport.pdf"));
JasperExportManager.exportReportToPdfStream(jasperPrint, out);
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (JRException e) {
System.out.println("JRException");
}
}
public static void main(String[] args) {
new PDF().genereazaRaport();
}
}
And I get a blank page when it save in file. I think it's something that has to do with the datasource but i can't figure what.

Try this jrxml. It will work for you.
<?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="FirstReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20"/>
<textElement/>
<text><![CDATA[If you don't see this, it didn't work
]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Enjoy...

Related

How to set Excel sheet name dynamically via JasperReports 6.x?

I have to upgrade jasperreport-4.0.2 to jasperreport-6.5.1 I found some differences regarding export reports to excel format as
net.sf.jasperreports.engine.export.JExcelApiExporter
Is deprecated and replaced by
net.sf.jasperreports.engine.export.JRXlsExporter
And many others things are also changed.
As in jasperreport-4.0.2 I can change excel sheet names as by this code
JRAbstractExporter exporter = new net.sf.jasperreports.engine.export.JExcelApiExporter();
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
What is alternate for naming excel sheets in jasperreport-6.5.1 is?
In accordance with the new API (comparing with 4.x version) you can solve the task in several ways.
Using ReportExportConfiguration
We can set sheet name using SimpleXlsxReportConfiguration, in thit case we should override getSheetNames() method.
Java code:
Map<String, Object> params = new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setConfiguration(new SimpleXlsxReportConfiguration() {
#Override
public String[] getSheetNames() {
return new String[]{"MyName"};
}
});
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimpleOutputStreamExporterOutput exporterOutput = null;
try (OutputStream outputStream = new FileOutputStream(file)) {
exporterOutput = new SimpleOutputStreamExporterOutput(outputStream);
exporter.setExporterOutput(exporterOutput);
exporter.exportReport();
} finally {
if (exporterOutput != null) {
exporterOutput.close();
}
}
Report template:
<?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="Set sheet name via exporter's configuration" pageWidth="595" pageHeight="200" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<title>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30"/>
<text><![CDATA[Set sheet name via exporter's configuration]]></text>
</staticText>
</band>
</title>
</jasperReport>
The generated result will be:
Using report's parameter and net.sf.jasperreports.export.xls.sheet.name property
The sheet name can be set with help of net.sf.jasperreports.export.xls.sheet.name property. In case we want set this name dynamically we can use report's parameter for passing the name.
Java code:
Map<String, Object> params = new HashMap<>();
params.put("stringParam", "ZZZ");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setConfiguration(new SimpleXlsxReportConfiguration());
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimpleOutputStreamExporterOutput exporterOutput = null;
try (OutputStream outputStream = new FileOutputStream(file)) {
exporterOutput = new SimpleOutputStreamExporterOutput(outputStream);
exporter.setExporterOutput(exporterOutput);
exporter.exportReport();
} finally {
if (exporterOutput != null) {
exporterOutput.close();
}
}
The report's template:
<?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="Set sheet name via parameter" pageWidth="595" pageHeight="200" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="name" class="java.lang.String"/>
<title>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30">
<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$P{name}]]></propertyExpression>
</reportElement>
<text><![CDATA[Set sheet name via parameter]]></text>
</staticText>
</band>
</title>
</jasperReport>
The result will be:
More information about using xls/xlsx exporters:
Advanced Excel Features

Expression Value in Jasper Report: “Cannot cast from ByteArrayInputStream to String” error

I am trying to convert an encoded tag in an xml to image and then convert into PDF using Java and Jaspersoft Studio.
NOTE : When I am previewing in Jasper studio I am getting proper display image but getting the above error while running it using Java main method.
Motive of the code is to fetch the tag from xml and convert it to pdf with image.
I am using JasperReports 6.4.0. While previewing from Jaspersoft Studio image is getting displayed properly and jrxml file is getting compiled too. But while running using main method in Java, I am getting error.
Below is the jrxml file I am using.
<?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="ImageDS" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString language="xPath">
<![CDATA[/Data/ListOfIdeaCafEntryFormIio/IdeaCafEntryFormBc]]>
</queryString>
<field name="Photo" class="java.lang.String">
<fieldDescription><![CDATA[Photo]]></fieldDescription>
</field>
<group name="Photo">
<groupExpression><![CDATA[$F{Photo}]]></groupExpression>
</group>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="206" y="0" width="100" height="30"/>
<text><![CDATA[Photo]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<image>
<reportElement x="205" y="52" width="50" height="50"/>
<imageExpression><![CDATA[new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{Photo}.getBytes()))]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
Java Code used to generate PDF :
public class Java8Base64Image {
public static void main(String[] args) {
BaseDao dao = new BaseDao();
Connection connection = dao.getConnection();
try {
String reportName = "C:/..../MyReports/ImageDS";
Map<String, Object> parameters = new HashMap<String, Object>();
JasperCompileManager.compileReportToFile(reportName + ".jrxml");
JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection);
// exports report to pdf
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(reportName + ".pdf"));
exporter.exportReport();
} catch (Exception e) {
throw new RuntimeException("It's not possible to generate the pdf report.", e);
} finally {
if (connection != null) {
try { connection.close(); } catch (Exception e) {}
}
}
}
}
XML with image:
<Photo>/9j/..../OiiiQon/9k=</Photo>
The error I got
Error is : Caused by: net.sf.jasperreports.engine.JRException:
Errors were encountered when compiling report expressions class file:
1. Cannot cast from ByteArrayInputStream to String value = (java.lang.String)(new java.io.ByteArrayInputStream(org.apache.commons.codec.binary‌​.Base64.decodeBase64‌​(((java.lang.String)‌​field_Photo.getValue‌​()).getBytes()))); //$JR_EXPR_ID=11$

Reuse same field structure / design in a report

I need to design a report to represent a pojo structure like the following:
class Obj{
field1;
field2;
List<Obj> substitutions;
}
My report will have the same field design, used one time in detail 1 band and then n-times in detail 2 with a subreport.
How can I reuse the same field design in both detail 1 and 2?
I have tryed to put a subreport in detail1 and a subreport in detail 2 pointing the same jrxml file. While the second report is ok because is filled by a collection in back object of report, I don't know how to pass current report datasource to first subreport.
Does someone have any ideas?
Here an example on the result report.
I have a pojo class named purchase.
public class Purchase {
private String name;
private String remark;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getRemark() {
return remark;
}
}
Main class to generate pdf file.
public class JasperReportIntro {
public static void main(String[] args) {
JasperReport jasperReport;
JasperPrint jasperPrint;
ArrayList<Purchase> list1 = new ArrayList<Purchase>();
ArrayList<Purchase> list2 = new ArrayList<Purchase>();
for(int i=0;i<20;i++) {
Purchase purchase = new Purchase();
purchase.setName("Vivek" + i);
purchase.setRemark("This is remark" + i);
purchase.setDiscount(10.0);
purchase.setId(i);
list1.add(purchase);
}
for(int i=0;i<20;i++) {
Purchase purchase = new Purchase();
purchase.setName("yadav" + i);
purchase.setRemark("This is remark" + i);
purchase.setDiscount(10.0);
purchase.setId(i);
list2.add(purchase);
}
try {
jasperReport = JasperCompileManager.compileReport("path/to/report.jrxml");
Map<String, List> result = new HashMap<String, List>();
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(list1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("dataForSubreport1",list1);
map.put("dataForSubreport2",list2);
jasperPrint = JasperFillManager.fillReport(jasperReport,map, beanCollectionDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint,
"path/to/simple_report.pdf");
System.out.println("Completed");
} catch (JRException e) {
e.printStackTrace();
}
}
}
Main report class report.jrxml.
<?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="report" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4ddfa540-9b62-4339-9334-18733f7469cc">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["/home/jft/code/jasper-report/Genratedreports/"]]></defaultValueExpression>
</parameter>
<parameter name="dataForSubreport1" class="java.util.List"/>
<parameter name="dataForSubreport2" class="java.util.List"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="100">
<subreport>
<reportElement x="0" y="20" width="555" height="40" uuid="8798ed7b-f389-4037-9381-3862d2f3e43a"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{dataForSubreport1})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "sub1.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement positionType="Float" x="0" y="60" width="555" height="40" uuid="f99fdb31-afc3-4127-8148-8e0426cd71a6"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{dataForSubreport2})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "sub1.jasper"]]></subreportExpression>
</subreport>
</band>
</title>
</jasperReport>
Here is subreport sub1.jrxml.
<?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="sub1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="48bc0742-6980-42a7-9a52-6f125fb83bc2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="name" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="ac3c1a86-6d0d-4b63-b339-744528573666"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Download file using main class of jasperreportintro. I have passed two parameter dataForSubreport1 and dataForSubreport2 using map. and send both parameter in subreport. It use same subreport with different -2 value. Hope it will help you.
Enjoy.

Creating Hindi PDF using UTF-8 in JasperReport

My requirement is to Create a PDF with some text in Hindi/Marathi/Other Indian Language while some text in English.
Text in Hindi/Marathi/Other Indian Language will be static text in Unicode (UTF-8) while text in English will be static and dynamic. I created a jrxml file in iReport 5.5.0. In iReport Internal Viewer, it shows proper output. However while exporting in pdf, it doesn't show the Hindi Text at all. It only shows English Text. While exporting in doc, the Hindi Text is coming as squares which I feel is word setting issue. In HTML or RTF export, it works perfectly. The same thing is happening when I create pdf/doc/html/rtf using Java Code. I am attaching Java and jrxml file over here for reference.
public class TestHindiPDF {
public static void main(String[] args) throws Exception {
String strJasperFilePath = null;
String strJRXMLFilePath = null;
String strReportPath = "D:\\Chintan\\Tech\\Input_Files\\TestMulti";
String strSaveReportPath = "D:\\Chintan\\Tech\\Input_Files\\TestMulti";
String strReportName = "multi1";
strJasperFilePath = strReportPath + "/multi1.jasper";
strJRXMLFilePath = strReportPath + "/multi1.jrxml";
strReportName = "multi1";
File reportFile = new File(strJasperFilePath);//your report_name.jasper file
if (!reportFile.exists()) {
try {
System.out.println("Compiling JRXML File : " + strJRXMLFilePath);
JasperCompileManager.compileReportToFile(strJRXMLFilePath, strJasperFilePath);
reportFile = new File(strJasperFilePath);
} catch (JRException e) {
e.printStackTrace();
}
}
if (reportFile != null) {
OutputStream fileOut = null;
try {
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JREmptyDataSource());
JRExporter exporter2 = new JRRtfExporter();
exporter2.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter2.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter2.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, strSaveReportPath + "/" + strReportName + ".rtf");
exporter2.exportReport();
JRExporter exporter3 = new JRHtmlExporter();
exporter3.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter3.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter3.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, strSaveReportPath + "/" + strReportName + ".html");
exporter3.exportReport();
JRExporter exporter4 = new JRDocxExporter();
exporter4.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter4.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter4.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, strSaveReportPath + "/" + strReportName + ".docx");
exporter4.exportReport();
JRExporter exporter1 = new JRPdfExporter();
exporter1.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter1.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter1.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, strSaveReportPath + "/" + strReportName + ".pdf");
exporter1.exportReport();
JasperExportManager.exportReportToPdfStream(jasperPrint, fileOut);
} catch (JRException e) {
e.printStackTrace();
} finally {
if (fileOut != null) {
fileOut.close();
}
}
}
}
}
The JRXML File is :
<?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="multi1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c8a053f6-858e-427b-aec1-89231aadddd6">
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="104" y="0" width="313" height="25" uuid="fa5e3e6e-26f7-4973-a2d5-3c3b7a5e8227"/>
<textElement textAlignment="Center">
<font size="16"/>
</textElement>
<text><![CDATA[अतिदेय राशि के पुनर्भुगतान हेतु अनुस्मारक]]></text>
</staticText>
<staticText>
<reportElement x="132" y="25" width="252" height="25" uuid="fa5e3e6e-26f7-4973-a2d5-3c3b7a5e8227"/>
<textElement textAlignment="Center">
<font size="16"/>
</textElement>
<text><![CDATA[Reminder for repaying Overdue Amount]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>

Generating a pdf report using JasperRunManager

I want to generate a pdf report using ejbql ,but I dont know how to do that.
I have tried to do thye following but an error occure:
parameterMap.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, entityManager);
parameterMap.put("priority", "3");
try
{
JasperFillManager.fillReportToFile("C:/Documents and Settings/MyDocuments/NetBeansProjects/JiraMap/src/java/Reports/Test.jasper", parameterMap);
JasperRunManager.runReportToPdfFile("C:/Documents and Settings/MyDocuments/NetBeansProjects/JiraMap/src/java/Reports/Test.pdf", parameterMap);
}
catch (JRException ex)
{
ex.printStackTrace();
}
Tehb error is:
net.sf.jasperreports.engine.JRException: Error loading object from file : C:\Documents and Settings\My Documents\NetBeansProjects\JiraMap\src\java\Reports\Test.pdf
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:101)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdfFile(JasperRunManager.java:93)
at Reporting.ReportBean.main(ReportBean.java:38)
Caused by: java.io.EOFException
UPdate
I have use this code (I haven't use any parameter ) but always the report is empty:
JasperReport report = JasperCompileManager.compileReport("C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/Test.jrxml");
JasperPrint print = JasperFillManager.fillReport(report,null);
JasperExportManager.exportReportToPdfFile(print,"C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/Test.pdf");
My report with the Aggregate Function count(I have tried to use the alias as numebr but it didn't work):
<?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="Test" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="priority" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString language="ejbql">
<![CDATA[select count(j) from Jiraissue j where j.priority='3']]>
</queryString>
<field name="count(j)" class="java.lang.Long"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="84" splitType="Stretch">
<staticText>
<reportElement x="28" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[count(j)]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="50" y="11" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Long"> <![CDATA[$F{count(j)}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The error is :
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : count(j)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDat aSource.java:123)
at net.sf.jasperreports.engine.data.JRJpaDataSource$PropertyReader.getValue(JRJpaDataSource.java:206)
at net.sf.jasperreports.engine.data.JRJpaDataSource.getFieldValue(JRJpaDataSource.java:131)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:821)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:785)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1482)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:126)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:118)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:435)
at Reporting.ReportBean.main(ReportBean.java:41)
Caused by: java.lang.NoSuchMethodException: Unknown property 'count'+ on bean class 'class java.lang.Long'
[EL Info]: 2011-06-29 11:05:12.606--ServerSession(27055962)--file:/C:/Documents and Settings/a497165/My Documents/NetBeansProjects/JiraMap/build/web/WEB-INF/classes/_JiraMapPU logout successful
at org.apache.commons.beanutils.PropertyUtilsBean.getMappedProperty(PropertyUtilsBean.java:624)
at org.apache.commons.beanutils.PropertyUtilsBean.getMappedProperty(PropertyUtilsBean.java:570)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:758)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:837)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
... 10 more
This is part of the code I used for generating with JasperPrint; and sending the file back to a browser response. This using JDBC though, not EJBQL. But the JasperReports part of the code is the same.
FileResolver fileResolver = new FileResolver() {
#Override
public File resolveFile(String fileName) {
return new File(getServletContext().getRealPath("/") + fileName);
}
};
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("REPORT_FILE_RESOLVER", fileResolver);
...... // blah blah
JasperPrint jrprint = JasperFillManager.fillReport(input, parameters, conn);
byte[] reportBytes;
jrprint.setName("MyFile." + fileFormat);
response.setContentType("APPLICATION/OCTET-STREAM");
String disHeader = "Attachment;Filename=\"MyFile.";
ServletOutputStream os = response.getOutputStream();
response.setHeader("Content-Disposition", disHeader);
reportBytes = JasperExportManager.exportReportToPdf(jrprint);
os.write(reportBytes);
You need to pass all the parameters needed as below:
JasperPrint jrprint = JasperFillManager.fillReport(input, parameters, connections);

Categories