Creating Hindi PDF using UTF-8 in JasperReport - java

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>

Related

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$

.jrxml to .jasper compile error field not found exception

Hi i'm new to jasper report.i'm using ireport for designing report.
I have created a simple report design, which have 2 fields name,addr.
public class R {
private String name;
private String addr;
public R(String name, String addr) {
super();
this.name = name;
this.addr = addr;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
}
.jrxml file
<?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="R" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4fd2f78e-344d-4371-ba1e-f86c2a81ef75">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="296" y="41" width="228" height="20" uuid="19aa39a0-45cf-4b36-b327-25b640f81d8a"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Address]]></text>
</staticText>
<staticText>
<reportElement x="36" y="41" width="215" height="20" uuid="baba8372-2215-439d-8b20-fd4ab054bbe5"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="296" y="0" width="228" height="20" uuid="c4de17e6-e5bc-4454-b38e-cc50acf18f0b"/>
<textFieldExpression><![CDATA[$F{addr}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="36" y="0" width="215" height="20" uuid="8283d8b6-a288-48ec-bd4a-36c2875f5cff"/>
<textFieldExpression><![CDATA[$F{name}]]></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>
Here i'm using array list as a data source.
When i click compile button on i report it shows error that
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :       1. Field not found : addr      2. Field not found : name
java code
public void runReport(String fileName, String outFileName) throws JRException
{
List<R> list = new ArrayList<R>();
Map parameters = new HashMap();
list.add(new R("a1" ,"a2"));
list.add(new R("b1" ,"b2"));
list.add(new R("c1" ,"c2"));
JasperPrint print = JasperFillManager.fillReport( fileName, parameters, new JRBeanCollectionDataSource(list));
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(
JRExporterParameter.OUTPUT_FILE_NAME,outFileName);
exporter.setParameter(
JRExporterParameter.JASPER_PRINT, print);
JasperExportManager.exportReportToPdfFile(print, outFileName);
print = null;
exporter = null;
}
You should add to your jrxml field:
<field name="addr" class="java.lang.String">
<fieldDescription><![CDATA[addr]]></fieldDescription></field>
You can do it by clicking on "fields" and selecting "create field".

JasperReports renders empty pdf

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...

Problem with charting using JasperReport

I have a problem when I generate a report,the problem is that chart repeats
exp if I have in the X axis 5 elements ,the chart will be repeated 5 times
My report:
<?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="BarChartproject" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="SQL" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[$P!{SQL}]]>
</queryString>
<field name="nb" class="java.lang.Long"/>
<field name="priority" class="java.lang.String"/>
<field name="project" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="18" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="178" splitType="Stretch">
<stackedBar3DChart>
<chart>
<reportElement x="70" y="21" width="363" height="132"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA[$F{project}]]></seriesExpression>
<categoryExpression><![CDATA[$F{project}]]></categoryExpression>
<valueExpression><![CDATA[$F{nb}]]></valueExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot/>
<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
<categoryAxisFormat>
<axisFormat>
<labelFont/>
<tickLabelFont/>
</axisFormat>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat>
<labelFont/>
<tickLabelFont/>
</axisFormat>
</valueAxisFormat>
</bar3DPlot>
</stackedBar3DChart>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
My code:
public String ConstructSQL()
{
System.out.println("status------"+this.getMyChoiceStatus());
System.out.println("chartssssssssss------"+this.getChartType());
for(int i=0;i<checkbox.length;i++)
{
if (checkbox[i].equals("1"))
{
System.out.println("priority checked");
select ="select count(jiraissue.id) as nb ,jiraissue.priority,jiraissue.project,jiraissue.issuestatus";
from =" from jiraissue,issuestatus";
where =" where issuestatus.id=jiraissue.issuestatus";
and =" and issuestatus.pname ="+"'"+this.getMyChoiceStatus()+"'";
groupBy=" group by jiraissue.priority";
sql =select+from+where+and+groupBy+" ;";
System.out.println("SQL report------"+this.sql);
return sql;
}
else
{
if (checkbox[i].equals("2"))
{
System.out.println("project checked");
select ="select count(jiraissue.id) as nb ,jiraissue.project,jiraissue.priority,jiraissue.issuestatus";
from =" from jiraissue,issuestatus";
where =" where issuestatus.id=jiraissue.issuestatus";
and =" and issuestatus.pname ="+"'"+this.getMyChoiceStatus()+"'";
groupBy=" group by jiraissue.project";
sql =select+from+where+and+groupBy+" ;";
System.out.println("SQL report------"+this.sql);
return sql;
}
}
}
return sql;
}
public void fillReport()
{
try {
// - Connexion à la base
Driver monDriver = new com.mysql.jdbc.Driver();
DriverManager.registerDriver(monDriver);
connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/jiradb", "","");
// - Chargement et compilation du rapport
JasperDesign jasperDesign = JRXmlLoader.load("C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/"+chartType+chartGrouping()+".jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map parameterMap = new HashMap();
parameterMap.put("SQL",ConstructSQL());
// // - Execution du rapport
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameterMap, connection);
// - Création du rapport au format PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/"+chartType+chartGrouping()+".pdf");
// JasperViewer.viewReport(jasperPrint);
}
I think the issue here (which you have most probably discovered already as this question was aksed 7 months ago) is that you have placed the chart into the 'Detail' area. You will have the detail area repeated for each element returned (i.e. row of data in a query).
You should place the chart into the 'Title' area, or one of the other 'non-repeating' areas on a page.

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