Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Printing jsf ArrayLIst via Jasper Report using JRBeanCollectionDataSource

  Asked By: Jamal    Date: Jan 17    Category: Java    Views: 3532
  

0 down vote favorite
share [fb] share [tw]


I'm using a jsf array list to retrieve records based on some criteria. Now I want contents of this array list to be print via Jasper report. I followed following steps.

1. Used empty datasource in Jasper report.
2. Created Fields in jasper reports as those of my bean properties.
3. Then I compiled the report to employeeList.jasper and placed that in my /reports /employeeReports/employeeList.jasper folder in jsf project (I'm using Eclipse).

I have then used following code to fill and show the pdf report


JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(this.srchdEmployeesList);
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) facesContext.getExternalContext().getResponse();
HashMap parameterMap = new HashMap();
JasperFillManager.fillReportToFile("/reports/employeeReports/employeeList.jasper", parameterMap, dataSource);
InputStream reportStream = facesContext.getExternalContext().getResourceAsStream("/reports/employessReports/employeeList.jasper");
ServletOutputStream servletOutputStream = response.getOutputStream();
Class.forName("oracle.jdbc.driver.OracleDriver");
Session hibernateSession = null;
hibernateSession = HibernateUtils.currentSession();
connection = hibernateSession.connection();
facesContext.responseComplete();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;");
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, connection);

connection.close();
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}


I recieve following error message and report do not show up

net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: \reports
\employeeReports\employeeList.jasper
Caused by: java.io.FileNotFoundException: \reports\employeeReports
\employeeList.jasper ... 34 more

Help in this regard would be highly appreciated. Bundles of thanks in advance.

Share: 

 

No Answers Found. Be the First, To Post Answer.